From a7a79dac3124bba51fa9fb90033122b2955cfd95 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Fri, 8 Sep 2023 17:55:53 +0200 Subject: [PATCH 1/3] Make `install_formats()` use internal data too ref #313 --- R/suggestions.R | 25 +++++------ tests/testdata/example-DESCRIPTION | 62 --------------------------- tests/testthat/test_install_formats.R | 9 ---- 3 files changed, 13 insertions(+), 83 deletions(-) delete mode 100644 tests/testdata/example-DESCRIPTION diff --git a/R/suggestions.R b/R/suggestions.R index e518292..5fb9a7d 100644 --- a/R/suggestions.R +++ b/R/suggestions.R @@ -15,7 +15,7 @@ install_formats <- function(...) { if (length(to_install)) { utils::install.packages(to_install, ...) } - return(TRUE) + invisible(TRUE) } uninstalled_formats <- function() { @@ -28,11 +28,12 @@ uninstalled_formats <- function() { # 1.2.0)`) suggested in the `DESCRIPTION` file. However, this seems a bit # recursive, as `devtools` or `remotes` are often also in the `Suggests` # field. - suggestions <- read.dcf(system.file("DESCRIPTION", package = utils::packageName(), mustWork = TRUE), fields = "Suggests") - suggestions <- parse_suggestions(suggestions) - common_suggestions <- c("bit64", "datasets", "devtools", "knitr", "magrittr", "testthat") - suggestions <- setdiff(suggestions, common_suggestions) - + ## suggestions <- read.dcf(system.file("DESCRIPTION", package = utils::packageName(), mustWork = TRUE), fields = "Suggests") + ## suggestions <- parse_suggestions(suggestions) + ## common_suggestions <- c("bit64", "datasets", "devtools", "knitr", "magrittr", "testthat") + ## suggestions <- setdiff(suggestions, common_suggestions) + all_functions <- unlist(rio_formats[rio_formats$type == "suggest", c("import_function", "export_function")], use.names = FALSE) + suggestions <- unique(na.omit(stringi::stri_extract_first(all_functions, regex = "[a-zA-Z0-9\\.]+"))) # which are not installed unlist(lapply(suggestions, function(x) { if (length(find.package(x, quiet = TRUE))) { @@ -43,9 +44,9 @@ uninstalled_formats <- function() { })) } -parse_suggestions <- function(suggestions) { - suggestions <- unlist(strsplit(suggestions, split = ",|, |\n")) - suggestions <- gsub("\\s*\\(.*\\)", "", suggestions) - suggestions <- sort(suggestions[suggestions != ""]) - suggestions -} +## parse_suggestions <- function(suggestions) { +## suggestions <- unlist(strsplit(suggestions, split = ",|, |\n")) +## suggestions <- gsub("\\s*\\(.*\\)", "", suggestions) +## suggestions <- sort(suggestions[suggestions != ""]) +## suggestions +## } diff --git a/tests/testdata/example-DESCRIPTION b/tests/testdata/example-DESCRIPTION deleted file mode 100644 index 80378f9..0000000 --- a/tests/testdata/example-DESCRIPTION +++ /dev/null @@ -1,62 +0,0 @@ -Package: rio -Type: Package -Title: A Swiss-Army Knife for Data I/O -Version: 0.5.12 -Date: 2018-07-06 -Authors@R: c(person("Jason", "Becker", role = "ctb", email = "jason@jbecker.co"), - person("Chung-hong", "Chan", role = "aut", email = "chainsawtiney@gmail.com"), - person("Geoffrey CH", "Chan", role = "ctb", email = "gefchchan@gmail.com"), - person("Thomas J.", "Leeper", - role = c("aut", "cre"), - email = "thosjleeper@gmail.com", - comment = c(ORCID = "0000-0003-4097-6326")), - person("Christopher", "Gandrud", role = "ctb"), - person("Andrew", "MacDonald", role = "ctb"), - person("Ista", "Zahn", role = "ctb"), - person("Stanislaus", "Stadlmann", role = "ctb"), - person("Ruaridh", "Williamson", role = "ctb", email = "ruaridh.williamson@gmail.com"), - person("Patrick", "Kennedy", role = "ctb"), - person("Ryan", "Price", email = "ryapric@gmail.com", role = "ctb")) -Description: Streamlined data import and export by making assumptions that - the user is probably willing to make: 'import()' and 'export()' determine - the data structure from the file extension, reasonable defaults are used for - data import and export (e.g., 'stringsAsFactors=FALSE'), web-based import is - natively supported (including from SSL/HTTPS), compressed files can be read - directly without explicit decompression, and fast import packages are used where - appropriate. An additional convenience function, 'convert()', provides a simple - method for converting between file types. -URL: https://github.com/leeper/rio -BugReports: https://github.com/leeper/rio/issues -Depends: - R (>= 2.15.0) -Imports: - tools, - stats, - utils, - foreign, - haven (>= 1.1.0), - curl (>= 0.6), - data.table (>= 1.9.8), - readxl (>= 0.1.1), - openxlsx, - tibble -Suggests: - datasets, - bit64, - testthat, - knitr, - magrittr, - clipr, - csvy, - feather, - fst, - jsonlite, - NANTUCKET, - readODS (>= 1.6.4), - readr, - rmatio, - xml2 (>= 1.2.0), - yaml -License: GPL-2 -VignetteBuilder: knitr -RoxygenNote: 6.0.1 diff --git a/tests/testthat/test_install_formats.R b/tests/testthat/test_install_formats.R index 0c28503..d4f0076 100644 --- a/tests/testthat/test_install_formats.R +++ b/tests/testthat/test_install_formats.R @@ -9,12 +9,3 @@ test_that("uninstalled_formats()", { expect_type(formats, "character") } }) - -test_that("install_formats()", { - suggestions <- read.dcf("../testdata/example-DESCRIPTION", - fields = "Suggests") - suggestions <- parse_suggestions(suggestions) - expect_true("NANTUCKET" %in% suggestions) - expect_true("readODS" %in% suggestions) - expect_false("devtools" %in% suggestions) -}) From 9d0590a44d34e0139c284da86d815c828b73066e Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Fri, 8 Sep 2023 18:04:47 +0200 Subject: [PATCH 2/3] Use stats::na.omit --- R/suggestions.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/suggestions.R b/R/suggestions.R index 5fb9a7d..4ec2fae 100644 --- a/R/suggestions.R +++ b/R/suggestions.R @@ -33,7 +33,7 @@ uninstalled_formats <- function() { ## common_suggestions <- c("bit64", "datasets", "devtools", "knitr", "magrittr", "testthat") ## suggestions <- setdiff(suggestions, common_suggestions) all_functions <- unlist(rio_formats[rio_formats$type == "suggest", c("import_function", "export_function")], use.names = FALSE) - suggestions <- unique(na.omit(stringi::stri_extract_first(all_functions, regex = "[a-zA-Z0-9\\.]+"))) + suggestions <- unique(stats::na.omit(stringi::stri_extract_first(all_functions, regex = "[a-zA-Z0-9\\.]+"))) # which are not installed unlist(lapply(suggestions, function(x) { if (length(find.package(x, quiet = TRUE))) { From f5b257a0e5d325eca1484ab38ce21045e9acdb72 Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Fri, 8 Sep 2023 18:01:41 +0200 Subject: [PATCH 3/3] Add a guide on how to update the internal data --- Makefile | 4 +++- data-raw/readme.md | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 data-raw/readme.md diff --git a/Makefile b/Makefile index b6af726..89cbc6d 100644 --- a/Makefile +++ b/Makefile @@ -8,10 +8,12 @@ NAMESPACE: R/* README.md: README.Rmd Rscript -e "knitr::knit('README.Rmd')" +R/sysdata.rda: data-raw/single.json + Rscript data-raw/convert.R README.html: README.md pandoc -o README.html README.md -../$(pkg)*.tar.gz: DESCRIPTION NAMESPACE README.md R/* man/* tests/testthat/* po/R-rio.pot +../$(pkg)*.tar.gz: DESCRIPTION NAMESPACE README.md R/* man/* tests/testthat/* po/R-rio.pot R/sysdata.rda cd ../ && R CMD build $(pkg) build: ../$(pkg)*.tar.gz diff --git a/data-raw/readme.md b/data-raw/readme.md new file mode 100644 index 0000000..5623ced --- /dev/null +++ b/data-raw/readme.md @@ -0,0 +1,11 @@ + +Please edit the json file if you have made change related to formats. + +`convert.R` will prettify the json file as well as regenerate the internal data (`R/sysdata.rda`) + +If you prefer, you can also use the `Makefile` + +```R +make R/sysdata.rda +``` +