diff --git a/NEWS.md b/NEWS.md index da150fc..8565725 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# rio 1.2.3 + +* Fix #453, don't nudge the user to install all suggested packages + # rio 1.2.2 * Fix #447 - remove an ancient artefact of Vignette generation, h/t Tim Taylor for the help. diff --git a/R/onLoad.R b/R/onLoad.R index c96e2dd..d67cda3 100644 --- a/R/onLoad.R +++ b/R/onLoad.R @@ -2,8 +2,8 @@ if (interactive()) { w <- uninstalled_formats() if (length(w)) { - msg <- "The following rio suggested packages are not installed: %s\nUse 'install_formats()' to install them" - packageStartupMessage(sprintf(msg, toString(sQuote(w)))) + msg <- "Some optional R packages were not installed and therefore some file formats are not supported. Check file support with show_unsupported_formats()" + packageStartupMessage(msg) } } } diff --git a/R/suggestions.R b/R/suggestions.R index 6206b35..7cf92be 100644 --- a/R/suggestions.R +++ b/R/suggestions.R @@ -1,7 +1,7 @@ #' @title Install rio's \sQuote{Suggests} Dependencies -#' @description This function installs various \sQuote{Suggests} dependencies for rio that expand its support to the full range of support import and export formats. These packages are not installed or loaded by default in order to create a slimmer and faster package build, install, and load. +#' @description Not all suggested packages are installed by default. These packages are not installed or loaded by default in order to create a slimmer and faster package build, install, and load. Use `show_unsupported_formats()` to check all unsupported formats. `install_formats()` installs all missing \sQuote{Suggests} dependencies for rio that expand its support to the full range of support import and export formats. #' @param \dots Additional arguments passed to [utils::install.packages()]. -#' @return `NULL` +#' @return For `show_unsupported_formats()`, if there is any missing unsupported formats, it return TRUE invisibly; otherwise FALSE. For `install_formats()` it returns TRUE invisibly if the installation is succuessful; otherwise errors. #' @examples #' \donttest{ #' if (interactive()) { @@ -20,3 +20,22 @@ uninstalled_formats <- function() { ## which are not installed suggested_packages[!R.utils::isPackageInstalled(suggested_packages)] } + +#' @rdname install_formats +show_unsupported_formats <- function() { + ## default_formats <- sort(unique(rio_formats$format[rio_formats$type == "import"])) + suggested_formats <- rio_formats[rio_formats$type == "suggest",] + suggested_formats$pkg <- vapply(strsplit(suggested_formats$import_function, "::"), FUN = `[`, FUN.VALUE = character(1), 1) + missing_pkgs <- uninstalled_formats() + suggested_formats$installed <- vapply(suggested_formats$pkg, function(x) x %in% missing_pkgs, logical(1), USE.NAMES = FALSE) + unsupported_formats <- suggested_formats[suggested_formats$installed,] + if (nrow(unsupported_formats) == 0) { + message("All default and optional formats are supported.") + return(invisible(FALSE)) + } + temp_display <- unsupported_formats[,c("input", "format", "pkg")] + colnames(temp_display)[3] <- "Suggested package" + print(temp_display) + message("These formats are not supported. If you need to use these formats, please either install the suggested packages individually, or install_formats() to install them all.") + return(invisible(TRUE)) +} diff --git a/README.Rmd b/README.Rmd index fa25cf0..cc04056 100644 --- a/README.Rmd +++ b/README.Rmd @@ -81,7 +81,13 @@ export(list(mtcars = mtcars, iris = iris), file = "mtcars.xlsx") ## Supported file formats -**rio** supports a wide range of file formats. To keep the package slim, several formats are supported via "Suggests" packages, which are not installed (or loaded) by default. To ensure rio is fully functional, install these packages the first time you use **rio** via: +**rio** supports a wide range of file formats. To keep the package slim, several formats are supported via "Suggests" packages, which are not installed (or loaded) by default. You can check which formats are **not** supported via: + +```R +show_unsupported_formats() +``` + +You can install the suggested packages individually, depending your own needs. If you want to install all suggested packages: ```R install_formats() diff --git a/README.md b/README.md index a9d2aae..4fc1aab 100644 --- a/README.md +++ b/README.md @@ -117,8 +117,15 @@ export(list(mtcars = mtcars, iris = iris), file = "mtcars.xlsx") **rio** supports a wide range of file formats. To keep the package slim, several formats are supported via “Suggests” packages, which are not -installed (or loaded) by default. To ensure rio is fully functional, -install these packages the first time you use **rio** via: +installed (or loaded) by default. You can check which formats are +**not** supported via: + +``` r +show_unsupported_formats() +``` + +You can install the suggested packages individually, depending your own +needs. If you want to install all suggested packages: ``` r install_formats() diff --git a/man/install_formats.Rd b/man/install_formats.Rd index b1bccf2..f823a69 100644 --- a/man/install_formats.Rd +++ b/man/install_formats.Rd @@ -2,18 +2,21 @@ % Please edit documentation in R/suggestions.R \name{install_formats} \alias{install_formats} +\alias{show_unsupported_formats} \title{Install rio's \sQuote{Suggests} Dependencies} \usage{ install_formats(...) + +show_unsupported_formats() } \arguments{ \item{\dots}{Additional arguments passed to \code{\link[utils:install.packages]{utils::install.packages()}}.} } \value{ -\code{NULL} +For \code{show_unsupported_formats()}, if there is any missing unsupported formats, it return TRUE invisibly; otherwise FALSE. For \code{install_formats()} it returns TRUE invisibly if the installation is succuessful; otherwise errors. } \description{ -This function installs various \sQuote{Suggests} dependencies for rio that expand its support to the full range of support import and export formats. These packages are not installed or loaded by default in order to create a slimmer and faster package build, install, and load. +Not all suggested packages are installed by default. These packages are not installed or loaded by default in order to create a slimmer and faster package build, install, and load. Use \code{show_unsupported_formats()} to check all unsupported formats. \code{install_formats()} installs all missing \sQuote{Suggests} dependencies for rio that expand its support to the full range of support import and export formats. } \examples{ \donttest{ diff --git a/tests/testthat/test_install_formats.R b/tests/testthat/test_install_formats.R deleted file mode 100644 index 96fc6f2..0000000 --- a/tests/testthat/test_install_formats.R +++ /dev/null @@ -1,9 +0,0 @@ -test_that("uninstalled_formats()", { - skip_on_cran() - formats <- uninstalled_formats() - if (is.null(formats)) { - expect_true(install_formats()) - } else { - expect_type(formats, "character") - } -}) diff --git a/tests/testthat/test_suggestions.R b/tests/testthat/test_suggestions.R new file mode 100644 index 0000000..7c57f21 --- /dev/null +++ b/tests/testthat/test_suggestions.R @@ -0,0 +1,30 @@ +test_that("uninstalled_formats()", { + skip_on_cran() + formats <- uninstalled_formats() + if (is.null(formats)) { + expect_true(install_formats()) + } else { + expect_type(formats, "character") + } +}) + + +test_that("show_unsupported_formats (in the fully supported environment) on CI", { + skip_on_cran() + for (pkg in attr(rio_formats, "suggested_packages")) { + skip_if_not_installed(pkg) + } + expect_false(show_unsupported_formats()) + expect_message(show_unsupported_formats(), "All default") +}) + +test_that("show_unsupported_formats (in the partial supported environment) on CI", { + skip_on_cran() + fake_uninstalled_formats <- function() { + return(c("readODS")) + } + with_mocked_bindings(code = { + expect_true(show_unsupported_formats()) + expect_message(show_unsupported_formats(), "These formats are not supported") + }, `uninstalled_formats` = fake_uninstalled_formats) +})