From f5a03d6e6cd44bbee6e908943935472939774fcc Mon Sep 17 00:00:00 2001 From: chainsawriot Date: Thu, 14 Sep 2023 14:32:21 +0200 Subject: [PATCH] Fix #363 [no ci] (#373) --- R/import.R | 2 +- R/import_list.R | 2 +- R/suggestions.R | 16 +++------------- R/utils.R | 7 ++----- 4 files changed, 7 insertions(+), 20 deletions(-) diff --git a/R/import.R b/R/import.R index 7b88bc28..19e77418 100644 --- a/R/import.R +++ b/R/import.R @@ -102,7 +102,7 @@ #' @export import <- function(file, format, setclass = getOption("rio.import.class", "data.frame"), which, ...) { .check_file(file, single_only = TRUE) - if (grepl("^http.*://", file)) { + if (R.utils::isUrl(file)) { file <- remote_to_local(file, format = format) } if ((file != "clipboard") && !file.exists(file)) { diff --git a/R/import_list.R b/R/import_list.R index 1a7c7c82..6691f2f8 100644 --- a/R/import_list.R +++ b/R/import_list.R @@ -87,7 +87,7 @@ import_list <- } .read_file_as_list <- function(file, which, setclass, rbind, rbind_label, ...) { - if (grepl("^http.*://", file)) { + if (R.utils::isUrl(file)) { file <- remote_to_local(file) } if (get_info(file)$format == "rdata") { diff --git a/R/suggestions.R b/R/suggestions.R index b6629eb5..18028405 100644 --- a/R/suggestions.R +++ b/R/suggestions.R @@ -11,23 +11,13 @@ #' @export install_formats <- function(...) { to_install <- uninstalled_formats() - - if (length(to_install)) { - utils::install.packages(to_install, ...) - } + utils::install.packages(to_install, ...) invisible(TRUE) } uninstalled_formats <- function() { all_functions <- unlist(rio_formats[rio_formats$type == "suggest", c("import_function", "export_function")], use.names = FALSE) 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))) { - NULL - } else { - x - } - })) + ## which are not installed + suggestions[!R.utils::isPackageInstalled(suggestions)] } - diff --git a/R/utils.R b/R/utils.R index 69bf002e..8b934141 100644 --- a/R/utils.R +++ b/R/utils.R @@ -25,7 +25,7 @@ get_info <- function(file) { if (tolower(file) == "clipboard") { return(.query_format(input = "clipboard", file = "clipboard")) } - if (!grepl("^http.*://", file)) { + if (isFALSE(R.utils::isUrl(file))) { ext <- tolower(tools::file_ext(file)) } else { parsed <- strsplit(strsplit(file, "?", fixed = TRUE)[[1]][1], "/", fixed = TRUE)[[1]] @@ -108,10 +108,7 @@ escape_xml <- function(x, replacement = c("&", """, "<", ">", "&a } .create_directory_if_not_exists <- function(file) { - file_dir <- dirname(normalizePath(file, mustWork = FALSE)) - if (!dir.exists(file_dir)) { - dir.create(file_dir, recursive = TRUE) - } + R.utils::mkdirs(dirname(normalizePath(file, mustWork = FALSE))) invisible(NULL) }