From 9d712900f64579e48d935473638b41d61a194a12 Mon Sep 17 00:00:00 2001 From: Jon Harmon Date: Thu, 5 Sep 2024 07:16:31 -0500 Subject: [PATCH] Remove lazyeval dependency. (#74) Closes #60. --- DESCRIPTION | 2 +- NEWS.md | 6 ++++-- R/gutenberg_download.R | 3 ++- R/gutenberg_works.R | 22 ++++++++++++---------- man/gutenbergr-package.Rd | 1 + tests/testthat/test-gutenberg_download.R | 12 ++++++++++++ 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 53011e2..4a985a5 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -5,6 +5,7 @@ Authors@R: c( person("Jon", "Harmon", , "jonthegeek@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-4781-4346")), person("Myfanwy", "Johnston", , "mrowlan1@gmail.com", role = "aut"), + person("Jordan", "Bradford", , "jrdnbradford@gmail.com", role = "aut"), person("David", "Robinson", , "admiral.david@gmail.com", role = c("aut", "cph")) ) Description: Download and process public domain works in the Project @@ -21,7 +22,6 @@ Imports: cli, dplyr, glue, - lazyeval, magrittr, purrr, readr, diff --git a/NEWS.md b/NEWS.md index 541e859..5851200 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,8 @@ # gutenbergr (development version) -* `gutenberg_get_all_mirrors()` has been added to retrieve mirror data (@jrdnbradford, #58) +* `gutenberg_download()` tries the `.txt` version of files when the `.zip` is unavailable (@jrdnbradford, #55). +* New function `gutenberg_get_all_mirrors()` retrieves all mirror data (@jrdnbradford, #58). +* The package infrastructure has been updated to make the package more robust and maintainable. # gutenbergr 0.2.4 @@ -14,7 +16,7 @@ * Updated metadata (#32, #29) * minor bug fixes and improvements, including removing broken url and updating documentation to comply with CRAN roxygen2 requirements (#30, #31, #35, #28). -* Changed maintainer (#30) +* Changed maintainer (#30). # gutenbergr 0.2.0 diff --git a/R/gutenberg_download.R b/R/gutenberg_download.R index a399896..9ef2699 100644 --- a/R/gutenberg_download.R +++ b/R/gutenberg_download.R @@ -129,7 +129,8 @@ try_gutenberg_download <- function(url) { "i" = "The book may have been archived.", "i" = "Alternatively, You may need to select a different mirror.", ">" = "See https://www.gutenberg.org/MIRRORS.ALL for options." - ) + ), + class = "gutenbergr-warning-download_failure" ) } return(ret) diff --git a/R/gutenberg_works.R b/R/gutenberg_works.R index cd85645..a23acbb 100644 --- a/R/gutenberg_works.R +++ b/R/gutenberg_works.R @@ -69,17 +69,19 @@ gutenberg_works <- function(..., languages = "en", distinct = TRUE, all_languages = FALSE, only_languages = TRUE) { - dots <- lazyeval::lazy_dots(...) - if (length(dots) > 0 && any(names(dots) != "")) { - cli::cli_abort( - c( - x = "We detected a named input.", - i = "Use == expressions, not named arguments.", - i = "For example, use gutenberg_works(author == 'Dickens, Charles'),", - i = "not gutenberg_works(author = 'Dickens, Charles')." + rlang::check_dots_unnamed( + error = function(e) { + cli::cli_abort( + c( + x = "We detected a named input.", + i = "Use == expressions, not named arguments.", + i = "For example, use gutenberg_works(author == 'Dickens, Charles'),", + i = "not gutenberg_works(author = 'Dickens, Charles')." + ), + call = rlang::env_parent() ) - ) - } + } + ) ret <- filter(gutenberg_metadata, ...) if (!is.null(languages)) { diff --git a/man/gutenbergr-package.Rd b/man/gutenbergr-package.Rd index 75d11dd..993c7ed 100644 --- a/man/gutenbergr-package.Rd +++ b/man/gutenbergr-package.Rd @@ -23,6 +23,7 @@ Useful links: Authors: \itemize{ \item Myfanwy Johnston \email{mrowlan1@gmail.com} + \item Jordan Bradford \email{jrdnbradford@gmail.com} \item David Robinson \email{admiral.david@gmail.com} [copyright holder] } diff --git a/tests/testthat/test-gutenberg_download.R b/tests/testthat/test-gutenberg_download.R index 2414234..523b598 100644 --- a/tests/testthat/test-gutenberg_download.R +++ b/tests/testthat/test-gutenberg_download.R @@ -29,3 +29,15 @@ test_that("gutenberg_download works", { ) expect_identical(test_result, gutenbergr::sample_books) }) + +test_that("try_gutenberg_download errors informatively with no return", { + local_mocked_bindings( + read_next = function(url) { + return(NULL) + } + ) + expect_warning( + try_gutenberg_download("https://example.com"), + class = "gutenbergr-warning-download_failure" + ) +})