Skip to content

Commit

Permalink
Fix #363 [no ci] (#373)
Browse files Browse the repository at this point in the history
  • Loading branch information
chainsawriot authored Sep 14, 2023
1 parent 64fef5d commit f5a03d6
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 20 deletions.
2 changes: 1 addition & 1 deletion R/import.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
2 changes: 1 addition & 1 deletion R/import_list.R
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
16 changes: 3 additions & 13 deletions R/suggestions.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
}

7 changes: 2 additions & 5 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -108,10 +108,7 @@ escape_xml <- function(x, replacement = c("&amp;", "&quot;", "&lt;", "&gt;", "&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)
}

Expand Down

0 comments on commit f5a03d6

Please sign in to comment.