From 3f5883d5336e4c3ed0ba3e583f9cef0c9ce7cf4c Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 23:36:14 -0700 Subject: [PATCH 01/19] add verbose option. on by default, off for tests --- R/zzz.R | 1 + tests/testthat/setup.R | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/R/zzz.R b/R/zzz.R index 7a30f74..0420d2d 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -1,6 +1,7 @@ .onLoad <- function(libname, pkgname) { # keeping this first option hardcoded on load for now options("DataPackageR_packagebuilding" = FALSE) + options("DataPackageR_verbose" = TRUE) # respect previous user setting for 'DataPackageR_interact' if set op <- options() op.DataPackageR <- list( diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 684da0e..f1885c3 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -4,7 +4,8 @@ withr::local_options( list( DataPackageR_interact = FALSE, - DataPackageR_packagebuilding = FALSE + DataPackageR_packagebuilding = FALSE, + DataPackageR_verbose = FALSE ), .local_envir = teardown_env() ) From cc1771ffec169313124d1bd0c3498653693ee62f Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 23:36:51 -0700 Subject: [PATCH 02/19] silence skeleton when verbose off --- R/skeleton.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/skeleton.R b/R/skeleton.R index 4f2138b..215703c 100644 --- a/R/skeleton.R +++ b/R/skeleton.R @@ -40,6 +40,9 @@ datapackage_skeleton <- r_object_names = character(), raw_data_dir = character(), dependencies = character()) { + if (! getOption('DataPackageR_verbose', TRUE)){ + withr::local_options(list(usethis.quiet = TRUE)) + } if (is.null(name)) { stop("Must supply a package name", call. = FALSE) } @@ -217,5 +220,5 @@ datapackage.skeleton <- function(name = NULL, } .cat_line <- function(...) { - cat(..., "\n", sep = "") + if (getOption('DataPackageR_verbose', TRUE)) cat(..., "\n", sep = "") } From 48bb91aa3152b20ec0d0b362bf671b1449b70066 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 23:41:28 -0700 Subject: [PATCH 03/19] silence interactive news file notification when not verbose --- R/prompt.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/prompt.R b/R/prompt.R index 19188a7..3250044 100644 --- a/R/prompt.R +++ b/R/prompt.R @@ -6,7 +6,9 @@ if (interactive()&interact) { cat(crayon::cyan("Enter a text description of the changes for the NEWS.md file.\n")) #nocov }else{ - cat(crayon::cyan("Non-interactive NEWS.md file update.\n")) + if (getOption('DataPackageR_verbose', TRUE)){ + cat(crayon::cyan("Non-interactive NEWS.md file update.\n")) + } } change_description <- ifelse( @@ -83,7 +85,7 @@ added <- objectlist[["added"]] deleted <- objectlist[["deleted"]] changed <- objectlist[["changed"]] - + .write_changes <- function(string, news_con, what = NULL) { if (length(string) != 0) { cat(crayon::cyan(paste0("* ",what,": ",string,"\n"))) @@ -95,7 +97,7 @@ .write_changes(added, news_con, "Added") .write_changes(deleted, news_con, "Deleted") .write_changes(changed, news_con, "Changed") - + #write the rest of the data writeLines(news_file_data, con = news_con, @@ -103,4 +105,4 @@ ) flush(news_con) close(news_con) -} \ No newline at end of file +} From 5e5a123e51e3bb1455f0b8c6114a473370a22834 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Mon, 15 Apr 2024 23:50:20 -0700 Subject: [PATCH 04/19] silence next steps when verbose is off --- R/build.R | 1 + 1 file changed, 1 insertion(+) diff --git a/R/build.R b/R/build.R index 113b1e2..f3019d7 100644 --- a/R/build.R +++ b/R/build.R @@ -116,6 +116,7 @@ package_build <- function(packageName = NULL, } .next_steps <- function() { + if (! getOption('DataPackageR_verbose', TRUE)) return(invisible(NULL)) cat(crayon::green(crayon::bold("Next Steps")), "\n") # nolint cat(crayon::white(crayon::yellow(crayon::bold("1. Update your package documentation.")), "\n")) # nolint cat(crayon::white(" - Edit the documentation.R file in the package source", crayon::green("data-raw"), "subdirectory and update the roxygen markup."), "\n") # nolint From a98fd8a8441e612fc900dca33acd4a5034d2ccda Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 00:05:04 -0700 Subject: [PATCH 05/19] silence devtools::build() when verbose is off --- R/build.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/R/build.R b/R/build.R index f3019d7..8efdda6 100644 --- a/R/build.R +++ b/R/build.R @@ -105,7 +105,8 @@ package_build <- function(packageName = NULL, .multilog_trace("Building package") location <- build(package_path, path = dirname(package_path), - vignettes = vignettes + vignettes = vignettes, + quiet = ! getOption('DataPackageR_verbose', TRUE) ) # try to install and then reload the package in the current session if (install) { From e6af304dd92302f920312764f7cb5ebbaae3f639 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 00:20:29 -0700 Subject: [PATCH 06/19] fix test that relied on console output --- tests/testthat/test-ignore.R | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/tests/testthat/test-ignore.R b/tests/testthat/test-ignore.R index 6666860..07328c6 100644 --- a/tests/testthat/test-ignore.R +++ b/tests/testthat/test-ignore.R @@ -4,18 +4,28 @@ test_that("use_ignore works", { file <- system.file("extdata", "tests", "subsetCars.Rmd", package = "DataPackageR" ) - expect_null( - datapackage_skeleton( - name = "subsetCars", - path = tempdir(), - code_files = c(file), - force = TRUE, - r_object_names = c("cars_over_20") + local({ + tempdir <- withr::local_tempdir() + expect_null( + datapackage_skeleton( + name = "subsetCars", + path = tempdir, + code_files = c(file), + force = TRUE, + r_object_names = c("cars_over_20") + ) ) - ) - #expect_output(use_ignore(file = "mydata.csv",path = "inst/extdata"),"Adding 'mydata.csv' to 'inst/extdata/\\.gitignore'|Adding '\\^inst/extdata/mydata\\\\.csv\\$' to '\\.Rbuildignore'") - withr::with_options(c(crayon.enabled = FALSE), { - expect_message(use_ignore(file = "mydata.csv", path = "inst/extdata"), "Adding 'mydata.csv' to 'inst/extdata/\\.gitignore'|Adding '\\^inst/extdata/mydata\\.csv\\$' to '\\.Rbuildignore'") + use_ignore(file = "mydata.csv", path = file.path("inst", "extdata")) + expect_true( + 'mydata.csv' %in% readLines( + file.path(tempdir, 'subsetCars', 'inst', 'extdata', '.gitignore') + ) + ) + expect_true( + '^inst/extdata/mydata\\.csv$' %in% readLines( + file.path(tempdir, 'subsetCars', '.Rbuildignore') + ) + ) + expect_message(use_ignore(),"No file name provided to ignore.") }) - expect_message(use_ignore(),"No file name provided to ignore.") }) From cda6c7af4f6923b2a66334896fc1045d7aa8237e Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 00:32:39 -0700 Subject: [PATCH 07/19] silence yaml console output when verbose is off --- R/yamlR.R | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/R/yamlR.R b/R/yamlR.R index b01f08c..7382243 100644 --- a/R/yamlR.R +++ b/R/yamlR.R @@ -7,7 +7,7 @@ #' @details Add, remove files and objects, enable or disable parsing of specific files, list objects or files in a yaml config, or write a config back to a package. #' @importFrom yaml yaml.load_file as.yaml write_yaml #' @importFrom stats runif -#' @importFrom withr with_options +#' @importFrom withr with_options #' @export #' #' @examples @@ -62,7 +62,7 @@ yml_add_files <- function(config, filenames) { config[["configuration"]][["files"]][[i]]$enabled <- TRUE } } - cat(yaml::as.yaml(config)) + if (getOption('DataPackageR_verbose', TRUE)) cat(yaml::as.yaml(config)) return(config) } @@ -111,7 +111,7 @@ yml_add_objects <- function(config, objects) { config[["configuration"]][["objects"]], objects )) - cat(yaml::as.yaml(config)) + if (getOption('DataPackageR_verbose', TRUE)) cat(yaml::as.yaml(config)) return(config) } @@ -123,8 +123,10 @@ yml_list_objects <- function(config) { # assume config is a package root path config <- yml_find(config) } - cat("\n") - cat(config[["configuration"]][["objects"]]) + if (getOption('DataPackageR_verbose', TRUE)){ + cat("\n") + cat(config[["configuration"]][["objects"]]) + } invisible(config[["configuration"]][["objects"]]) } @@ -135,8 +137,10 @@ yml_list_files <- function(config) { # assume config is a package root path config <- yml_find(config) } - cat("\n") - cat(names(config[["configuration"]][["files"]])) + if (getOption('DataPackageR_verbose', TRUE)){ + cat("\n") + cat(names(config[["configuration"]][["files"]])) + } invisible(names(config[["configuration"]][["files"]])) } @@ -152,7 +156,7 @@ yml_remove_objects <- function(config, objects) { config[["configuration"]][["objects"]], objects ) - cat(yaml::as.yaml(config)) + if (getOption('DataPackageR_verbose', TRUE)) cat(yaml::as.yaml(config)) return(config) } @@ -168,7 +172,7 @@ yml_remove_files <- function(config, filenames) { config[["configuration"]][["files"]][[i]] <- NULL } } - cat(yaml::as.yaml(config)) + if (getOption('DataPackageR_verbose', TRUE)) cat(yaml::as.yaml(config)) return(config) } @@ -237,7 +241,7 @@ construct_yml_config <- function(code = NULL, data = NULL, render_root = NULL) { for (i in code) { files[[i]]$enabled <- TRUE } - + # create render root at a temporary directory. # this will be stored in the yaml. What if we restart? # see processData - it gets validated and created if not existing. From 24cd7d6f5e4b7af47ef2b860272d4a843da1cdc6 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 00:50:23 -0700 Subject: [PATCH 08/19] silence console about changed objects when verbose off --- R/prompt.R | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/R/prompt.R b/R/prompt.R index 3250044..ecf5663 100644 --- a/R/prompt.R +++ b/R/prompt.R @@ -88,7 +88,9 @@ .write_changes <- function(string, news_con, what = NULL) { if (length(string) != 0) { - cat(crayon::cyan(paste0("* ",what,": ",string,"\n"))) + if (getOption('DataPackageR_verbose', TRUE)){ + cat(crayon::cyan(paste0("* ",what,": ",string,"\n"))) + } writeLines(text = paste0("* ",what,": ", string), con = news_con, sep = "\n") From 4b5564175c44d58bc7edd622d7e87d68da5ac006 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 00:51:03 -0700 Subject: [PATCH 09/19] rm random line break cat to console --- R/processData.R | 1 - 1 file changed, 1 deletion(-) diff --git a/R/processData.R b/R/processData.R index a6c9e3b..5f20436 100644 --- a/R/processData.R +++ b/R/processData.R @@ -504,7 +504,6 @@ DataPackageR <- function(arg = NULL, deps = TRUE) { .ppfiles_mkvignettes <- function(dir = NULL) { - cat("\n") if (proj_get() != dir) { usethis::proj_set(dir) #nocov } From ee77c763ff353d24e82919611d8e9ebc6a6496fc Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 00:58:36 -0700 Subject: [PATCH 10/19] verbose silencing within function DataPackageR --- R/processData.R | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/R/processData.R b/R/processData.R index 5f20436..046f47b 100644 --- a/R/processData.R +++ b/R/processData.R @@ -31,9 +31,12 @@ #' @importFrom utils getSrcref modifyList #' @importFrom usethis proj_set proj_get DataPackageR <- function(arg = NULL, deps = TRUE) { + if (! getOption('DataPackageR_verbose', TRUE)){ + withr::local_options(list(usethis.quiet = TRUE)) + } pkg_dir <- arg pkg_dir <- normalizePath(pkg_dir, winslash = "/") - cat("\n") + if (getOption('DataPackageR_verbose', TRUE)) cat("\n") usethis::proj_set(path = pkg_dir) raw_data_dir <- "data-raw" target <- normalizePath(file.path(pkg_dir, raw_data_dir), winslash = "/") From b8d42e9be30d8b01d6d7594c95158c89e221f073 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 01:36:10 -0700 Subject: [PATCH 11/19] silence attempting to create msg when verbose is off --- R/use.R | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/R/use.R b/R/use.R index 977e519..53d2064 100644 --- a/R/use.R +++ b/R/use.R @@ -4,8 +4,8 @@ #' the inst/extdata directory. #' #' @param path \code{character} path to file or directory. -#' @param ignore \code{logical} whether to ignore the path or file in git and R build. -#' +#' @param ignore \code{logical} whether to ignore the path or file in git and R build. +#' #' @return invisibly returns TRUE for success. Stops on failure. #' @importFrom usethis proj_get proj_set create_package use_data_raw #' @importFrom utils file_test @@ -42,7 +42,7 @@ use_raw_dataset <- function(path = NULL, ignore = FALSE) { overwrite = TRUE ) if (ignore) { - # inst/extdata is a path relative to the project root + # inst/extdata is a path relative to the project root # as needed by git_ignore use_ignore(basename(raw_file), path = file.path("inst", "extdata")) } @@ -68,7 +68,7 @@ use_raw_dataset <- function(path = NULL, ignore = FALSE) { #' #' The Rmd or R file or directory specified by \code{file} will be moved into #' the data-raw directory. It will also be added to the yml configuration file. -#' Any existing file by that name will be overwritten when overwrite is set to TRUE +#' Any existing file by that name will be overwritten when overwrite is set to TRUE #' #' @param file \code{character} path to an existing file or name of a new R or Rmd file to create. #' @param title \code{character} title of the processing script for the yaml header. Used only if file is being created. @@ -112,7 +112,7 @@ use_processing_script <- function(file = NULL, title = NULL, author = NULL, over } } raw_file <- suppressWarnings(normalizePath(file)) - + if (utils::file_test("-f", raw_file)) { # test if it's an R or Rmd file. if (!(grepl("\\.rmd$", tolower(raw_file)) | @@ -141,7 +141,9 @@ use_processing_script <- function(file = NULL, title = NULL, author = NULL, over !overwrite) { .bullet(paste0("Skipping file creation: pass overwrite = TRUE to use_processing_script()"), bullet = crayon::red("\u2622")) #nolint } else { - cat("Attempting to create ", raw_file) + if (getOption('DataPackageR_verbose', TRUE)){ + cat("Attempting to create ", raw_file) + } file.create(file.path(proj_path, "data-raw", basename(raw_file))) .update_header(file.path(proj_path, "data-raw", From 387d1cd9f01c5477f4e6908b935d972674069f86 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 10:22:16 -0700 Subject: [PATCH 12/19] silence console logger when verbose is FALSE --- R/logger.R | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/R/logger.R b/R/logger.R index 14016c0..37aa51a 100644 --- a/R/logger.R +++ b/R/logger.R @@ -27,6 +27,16 @@ flog.threshold(console, name = "console") flog.threshold(logfile, name = "logfile") } + +select_console_appender <- function(){ + if (getOption('DataPackageR_verbose', TRUE)){ + appender.console() + } else { + # quiet console appender + function(line) { } + } +} + .multilog_setup <- function(LOGFILE = NULL) { if (!is.null(LOGFILE)) { flog.logger( @@ -37,7 +47,7 @@ } flog.logger( name = "console", - appender = appender.console(), + appender = select_console_appender(), threshold = INFO ) } From efc657c78005b61ad3da4e9f783ac9949751343f Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 10:30:50 -0700 Subject: [PATCH 13/19] use verbose = TRUE during logger tests --- tests/testthat/test-logger.R | 56 +++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/tests/testthat/test-logger.R b/tests/testthat/test-logger.R index 3f0270e..5824fb7 100644 --- a/tests/testthat/test-logger.R +++ b/tests/testthat/test-logger.R @@ -1,29 +1,31 @@ context("logger") -test_that(".multilog_setup", { - expect_null(DataPackageR:::.multilog_setup(file.path(tempdir(), "test.log"))) -}) -test_that(".multilog_threshold", { - expect_null(DataPackageR:::.multilog_thresold(INFO, TRACE)) -}) -test_that(".multilog_info", { - expect_output(DataPackageR:::.multilog_info("message"), "INFO .* message") - expect_true(file_test("-f", file.path(tempdir(), "test.log"))) -}) -test_that(".multilog_error", { - expect_output(DataPackageR:::.multilog_error("message"), "ERROR .* message") -}) -test_that(".multilog_trace", { - expect_silent(DataPackageR:::.multilog_trace("message")) - expect_true(length(grep(pattern = "TRACE", - readLines(file.path(tempdir(), - "test.log")))) > 0) -}) -test_that(".multilog_warn", { - expect_output(DataPackageR:::.multilog_warn("message"), "WARN") -}) -test_that(".multilog_debug", { - expect_silent(DataPackageR:::.multilog_debug("message")) - expect_true(length(grep(pattern = "DEBUG", - readLines(file.path(tempdir(), - "test.log")))) > 0) +withr::with_options(list(DataPackageR_verbose = TRUE),{ + test_that(".multilog_setup", { + expect_null(DataPackageR:::.multilog_setup(file.path(tempdir(), "test.log"))) + }) + test_that(".multilog_threshold", { + expect_null(DataPackageR:::.multilog_thresold(INFO, TRACE)) + }) + test_that(".multilog_info", { + expect_output(DataPackageR:::.multilog_info("message"), "INFO .* message") + expect_true(file_test("-f", file.path(tempdir(), "test.log"))) + }) + test_that(".multilog_error", { + expect_output(DataPackageR:::.multilog_error("message"), "ERROR .* message") + }) + test_that(".multilog_trace", { + expect_silent(DataPackageR:::.multilog_trace("message")) + expect_true(length(grep(pattern = "TRACE", + readLines(file.path(tempdir(), + "test.log")))) > 0) + }) + test_that(".multilog_warn", { + expect_output(DataPackageR:::.multilog_warn("message"), "WARN") + }) + test_that(".multilog_debug", { + expect_silent(DataPackageR:::.multilog_debug("message")) + expect_true(length(grep(pattern = "DEBUG", + readLines(file.path(tempdir(), + "test.log")))) > 0) + }) }) From 0cbae2fdeef8d3b7aba4265ab0a987dde7da50c6 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 12:17:57 -0700 Subject: [PATCH 14/19] silence object_read when verbose = FALSE --- R/environments.R | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/R/environments.R b/R/environments.R index c97c17c..b6d5450 100644 --- a/R/environments.R +++ b/R/environments.R @@ -42,12 +42,16 @@ datapackager_object_read <- function(name) { temp_folder_path<-file.path(tempdir(),yml_find(usethis::proj_get())[["configuration"]][["render_root"]]$tmp) if(file.exists(objectPath<-file.path(temp_folder_path,paste0(name,".rds")))){ - message('loading ',name,' from temporary folder from previous build attempt.') + if (getOption('DataPackageR_verbose', TRUE)){ + message('loading ',name,' from temporary folder from previous build attempt.') + } object<-readRDS(objectPath) }else if(file.exists(objectPath<-file.path(project_data_path(),paste0(name,".rda")))){ - message('loading ',name,' from data directory.') - print(objectPath) + if (getOption('DataPackageR_verbose', TRUE)){ + message('loading ',name,' from data directory.') + print(objectPath) + } load_env<-new.env() load(objectPath,envir = load_env) object<-load_env[[ls(load_env)[1]]] From adb1fb68481cb0231f99a34c7a941aa3f18cf7c4 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 12:36:30 -0700 Subject: [PATCH 15/19] silence newline when not verbose --- R/processData.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/processData.R b/R/processData.R index 046f47b..37125cf 100644 --- a/R/processData.R +++ b/R/processData.R @@ -750,7 +750,7 @@ project_data_path <- function(file = NULL) { #' } #' } document <- function(path = ".", install = TRUE, ...) { - cat("\n") + if (getOption('DataPackageR_verbose', TRUE)) cat("\n") usethis::proj_set(path = path) path <- usethis::proj_get() assert_that(file.exists(file.path(path, "data-raw", "documentation.R"))) From fa9b43cc366b3594773a8af7556ccca041350566 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 12:36:59 -0700 Subject: [PATCH 16/19] silence installation progress in tests when not verbose --- tests/testthat/test-document.R | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-document.R b/tests/testthat/test-document.R index 8ce4a24..2491a2b 100644 --- a/tests/testthat/test-document.R +++ b/tests/testthat/test-document.R @@ -15,7 +15,10 @@ test_that("documentation is built via document()", { temp_libpath <- file.path(tempdir, "lib") dir.create(temp_libpath) package_build(file.path(tempdir, "subsetCars")) - expect_true(document(file.path(tempdir, "subsetCars"), lib = temp_libpath)) + expect_true(document( + file.path(tempdir, "subsetCars"), + lib = temp_libpath, + quiet = ! getOption('DataPackageR_verbose', TRUE))) docfile <- readLines(file.path( tempdir, "subsetCars", "data-raw", "documentation.R" @@ -47,7 +50,8 @@ NULL close(connection) expect_true( document(file.path(tempdir, "subsetCars"), - lib = temp_libpath) + lib = temp_libpath, + quiet = ! getOption('DataPackageR_verbose', TRUE)) ) v <- vignette(package = "subsetCars", lib.loc = temp_libpath) expect_equal(v$results[, "Item"], "subsetCars") From bb746ec3276ecb07d8073acb7aee311cb7a14f75 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 12:46:14 -0700 Subject: [PATCH 17/19] silence installation progress in tests when not verbose --- tests/testthat/test-r-processing.R | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-r-processing.R b/tests/testthat/test-r-processing.R index 777f34d..3e3e803 100644 --- a/tests/testthat/test-r-processing.R +++ b/tests/testthat/test-r-processing.R @@ -21,7 +21,8 @@ test_that("R file processing works and creates vignettes", { basename(package_build( file.path(tempdir, "rfiletest"), install = TRUE, - lib = temp_libpath + lib = temp_libpath, + quiet = ! getOption('DataPackageR_verbose', TRUE) )), "rfiletest_1.0.tar.gz" ) @@ -56,7 +57,8 @@ test_that("R file processing works and creates vignettes", { package_build( file.path(tempdir, "rfiletest"), install = TRUE, - lib = temp_libpath + lib = temp_libpath, + quiet = ! getOption('DataPackageR_verbose', TRUE) ) ), "rfiletest_1.0.tar.gz" From 9ba7f23945586a0c4874ef683e34e60c83a315a8 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 13:17:54 -0700 Subject: [PATCH 18/19] properly catch the error --- R/build.R | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/R/build.R b/R/build.R index 8efdda6..336aafe 100644 --- a/R/build.R +++ b/R/build.R @@ -74,17 +74,16 @@ package_build <- function(packageName = NULL, } # This should always be a proper name of a directory, either current or a # subdirectory - if (inherits( - try(is_r_package$find_file(path = package_path)) - , "try-error" - )) { - flog.fatal(paste0( - package_path, - " is not a valid R package directory beneath ", - getwd() - ), name = "console") - stop("exiting", call. = FALSE) - } + tryCatch({is_r_package$find_file(path = package_path)}, + error = function(cond){ + flog.fatal(paste0( + package_path, + " is not a valid R package directory beneath ", + getwd() + ), name = "console") + stop("exiting", call. = FALSE) + } + ) # Return success if we've processed everything success <- From ffa9282916773c75a6fbccfb67b553a9e3867633 Mon Sep 17 00:00:00 2001 From: Dave Slager Date: Tue, 16 Apr 2024 15:55:55 -0700 Subject: [PATCH 19/19] document package options --- R/DataPackageR-package.R | 34 ++++++++++++++++++++++++++++++++++ man/DataPackageR_options.Rd | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 man/DataPackageR_options.Rd diff --git a/R/DataPackageR-package.R b/R/DataPackageR-package.R index 309ac26..419b0a5 100644 --- a/R/DataPackageR-package.R +++ b/R/DataPackageR-package.R @@ -86,3 +86,37 @@ ## usethis namespace: start ## usethis namespace: end NULL + +#' Options consulted by DataPackageR +#' +#' @description User-configurable options consulted by DataPackageR, which +#' provide a mechanism for setting default behaviors for various functions. +#' +#' If the built-in defaults don't suit you, set one or more of these options. +#' Typically, this is done in the \code{.Rprofile} startup file, which you can open +#' for editing with \code{usethis::edit_r_profile()} - this will set the specified +#' options for all future R sessions. The following setting is recommended to +#' not be prompted upon each package build for a NEWS update: +#' +#' \code{options(DataPackageR_interact = FALSE)} +#' +#' @section Options for the DataPackageR package: +#' +#' - \code{DataPackageR_interact}: Upon package load, this defaults to the value of +#' \code{interactive()}, unless the option has been previously set (e.g., in +#' \code{.Rprofile}). TRUE prompts user interactively for a NEWS update on +#' \code{package_build()}. See the example above and the [rOpenSci blog +#' post](https://ropensci.org/blog/2018/09/18/datapackager/) for more details +#' on how to set this to FALSE, which will never prompt user for a NEWS +#' update. FALSE is also the setting used for DataPackageR's internal tests. +#' +#' - \code{DataPackageR_verbose}: Default upon package load is TRUE. FALSE suppresses +#' all console output and is currently only used for DataPackageR's automated +#' unit tests. +#' +#' - \code{DataPackageR_packagebuilding}: Default upon package load is FALSE. This +#' option is used internally for package operations and changing it is not +#' recommended. +#' +#' @name DataPackageR_options +NULL diff --git a/man/DataPackageR_options.Rd b/man/DataPackageR_options.Rd new file mode 100644 index 0000000..57acc90 --- /dev/null +++ b/man/DataPackageR_options.Rd @@ -0,0 +1,37 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/DataPackageR-package.R +\name{DataPackageR_options} +\alias{DataPackageR_options} +\title{Options consulted by DataPackageR} +\description{ +User-configurable options consulted by DataPackageR, which + provide a mechanism for setting default behaviors for various functions. + + If the built-in defaults don't suit you, set one or more of these options. + Typically, this is done in the \code{.Rprofile} startup file, which you can open + for editing with \code{usethis::edit_r_profile()} - this will set the specified + options for all future R sessions. The following setting is recommended to + not be prompted upon each package build for a NEWS update: + +\code{options(DataPackageR_interact = FALSE)} +} +\section{Options for the DataPackageR package}{ + + +- \code{DataPackageR_interact}: Upon package load, this defaults to the value of + \code{interactive()}, unless the option has been previously set (e.g., in + \code{.Rprofile}). TRUE prompts user interactively for a NEWS update on + \code{package_build()}. See the example above and the [rOpenSci blog + post](https://ropensci.org/blog/2018/09/18/datapackager/) for more details + on how to set this to FALSE, which will never prompt user for a NEWS + update. FALSE is also the setting used for DataPackageR's internal tests. + +- \code{DataPackageR_verbose}: Default upon package load is TRUE. FALSE suppresses + all console output and is currently only used for DataPackageR's automated + unit tests. + +- \code{DataPackageR_packagebuilding}: Default upon package load is FALSE. This + option is used internally for package operations and changing it is not + recommended. +} +