ianmcook commented on a change in pull request #9800: URL: https://github.com/apache/arrow/pull/9800#discussion_r607430655
########## File path: r/R/filesystem.R ########## @@ -273,33 +273,53 @@ FileSystem$from_uri <- function(uri) { fs___FileSystemFromUri(uri) } -get_path_and_filesystem <- function(x, filesystem = NULL) { +get_paths_and_filesystem <- function(x, filesystem = NULL) { # Wrapper around FileSystem$from_uri that handles local paths # and an optional explicit filesystem if (inherits(x, "SubTreeFileSystem")) { return(list(fs = x$base_fs, path = x$base_path)) } - assert_that(is.string(x)) - if (is_url(x)) { + assert_that(is.character(x)) + are_urls <- are_urls(x) + if (any(are_urls)) { + if (!all(are_urls)) { + stop("Vectors of mixed paths and URIs are not supported", call. = FALSE) + } if (!is.null(filesystem)) { # Stop? Can't have URL (which yields a fs) and another fs } - FileSystem$from_uri(x) + # TODO: do this more efficiently? + x <- lapply(x, FileSystem$from_uri) + if (length(unique(map(x, ~class(.$fs)))) > 1) { + stop( + "Vectors of URIs for different file systems are not supported", + call. = FALSE + ) + } + fs <- x[[1]]$fs + path <- map_chr(x, ~.$path) # singular name "path" used for compatibility } else { fs <- filesystem %||% LocalFileSystem$create() - path <- ifelse( - inherits(fs, "LocalFileSystem"), - clean_path_abs(x), - clean_path_rel(x) - ) - list( - fs = fs, - path = path - ) + if (inherits(fs, "LocalFileSystem")) { + path <- clean_path_abs(x) + } else { + path <- clean_path_rel(x) + } } + list( + fs = fs, + path = path + ) +} + +# variant of the above function that asserts length(x) == 1 +get_path_and_filesystem <- function(x, filesystem = NULL) { + assert_that(length(x) == 1) Review comment: Fixed in 741ba28535fb9ed433780915541b0b421c0b77f7 -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org