diff --git a/R/gutenberg_download.R b/R/gutenberg_download.R index 57428b0..63b9635 100644 --- a/R/gutenberg_download.R +++ b/R/gutenberg_download.R @@ -149,7 +149,13 @@ read_next <- function(possible_urls) { } } - +#' Join metadata fields to Gutenberg works +#' +#' @param gutenberg_tbl A two column `tbl_df` from `gutenberg_download`. +#' @inheritParams gutenberg_download +#' +#' @return A `tbl_df` of the Gutenberg works with joined metadata. +#' @keywords internal gutenberg_add_metadata <- function(gutenberg_tbl, meta_fields) { meta_fields <- union("gutenberg_id", meta_fields) dplyr::left_join( diff --git a/man/gutenberg_add_metadata.Rd b/man/gutenberg_add_metadata.Rd new file mode 100644 index 0000000..6203989 --- /dev/null +++ b/man/gutenberg_add_metadata.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/gutenberg_download.R +\name{gutenberg_add_metadata} +\alias{gutenberg_add_metadata} +\title{Join metadata fields to Gutenberg works} +\usage{ +gutenberg_add_metadata(gutenberg_tbl, meta_fields) +} +\arguments{ +\item{gutenberg_tbl}{A two column \code{tbl_df} from \code{gutenberg_download}.} + +\item{meta_fields}{Additional fields describing each book, such as \code{title} +and \code{author}, to add from \link{gutenberg_metadata}.} +} +\value{ +A \code{tbl_df} of the Gutenberg works with joined metadata. +} +\description{ +Join metadata fields to Gutenberg works +} +\keyword{internal} diff --git a/tests/testthat/test-data.R b/tests/testthat/test-data.R new file mode 100644 index 0000000..259bf5e --- /dev/null +++ b/tests/testthat/test-data.R @@ -0,0 +1,11 @@ +test_that("All four datasets have a date-updated", { + d1 <- attr(gutenberg_metadata, "date_updated") + d2 <- attr(gutenberg_subjects, "date_updated") + d3 <- attr(gutenberg_authors, "date_updated") + d4 <- attr(gutenberg_languages, "date_updated") + + expect_s3_class(d1, "Date") + expect_s3_class(d2, "Date") + expect_s3_class(d3, "Date") + expect_s3_class(d4, "Date") +}) diff --git a/tests/testthat/test-metadata.R b/tests/testthat/test-gutenberg_works.R similarity index 81% rename from tests/testthat/test-metadata.R rename to tests/testthat/test-gutenberg_works.R index 4301db2..ec87554 100644 --- a/tests/testthat/test-metadata.R +++ b/tests/testthat/test-gutenberg_works.R @@ -52,16 +52,3 @@ test_that("gutenberg_works gives error messages with named arguments", { "named arguments" ) }) - - -test_that("All four datasets have a date-updated", { - d1 <- attr(gutenberg_metadata, "date_updated") - d2 <- attr(gutenberg_subjects, "date_updated") - d3 <- attr(gutenberg_authors, "date_updated") - d4 <- attr(gutenberg_languages, "date_updated") - - expect_s3_class(d1, "Date") - expect_s3_class(d2, "Date") - expect_s3_class(d3, "Date") - expect_s3_class(d4, "Date") -})