Dynamically handle a local or remote file path

localOrRemoteFile(file)

Arguments

file

character(1). Local file paths or remote URLs.

Value

character. Local file path(s). Stops on a missing file.

Note

Updated 2019-07-19.

Vectorization

This function is vectorized and supports mixed local and remote paths. Remote files are downloaded locally to a temporary directory.

Compressed files

Compressed files will automatically be decompressed. Currently, these file extensions are natively supported: BZ2, GZ, XZ, ZIP.

See also

Examples

## Local file <- system.file("extdata/example.csv", package = "brio") x <- localOrRemoteFile(file) basename(x)
#> [1] "example.csv"
## Remote file <- pasteURL(brioTestsURL, "hgnc.txt.gz", protocol = "none") x <- localOrRemoteFile(file)
#> Decompressing 'hgnc.txt.gz' in 'tempdir()'
#> [1] "hgnc.txt"