Skip to content

Commit

Permalink
Make install_formats() use internal data too ref #313
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot committed Sep 8, 2023
1 parent 44eb387 commit 9b08995
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 83 deletions.
25 changes: 13 additions & 12 deletions R/suggestions.R
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ install_formats <- function(...) {
if (length(to_install)) {
utils::install.packages(to_install, ...)
}
return(TRUE)
invisible(TRUE)
}

uninstalled_formats <- function() {
Expand All @@ -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))) {
Expand All @@ -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
## }
62 changes: 0 additions & 62 deletions tests/testdata/example-DESCRIPTION

This file was deleted.

9 changes: 0 additions & 9 deletions tests/testthat/test_install_formats.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

0 comments on commit 9b08995

Please sign in to comment.