get_file_size() returns the sizes of files in bytes. It works with local
and remote files.
Arguments
- file
A
charactervector of file paths. The function also works with URLs.- connection_timeout
(optional) A
numericvalue specifying the connection timeout in seconds for HTTP requests (default:10).- max_tries
(optional) A
numericvalue specifying the maximum number of retry attempts (default:3).- retry_on_failure
(optional) A
logicalvalue indicating whether to retry on failure (default:TRUE).
Value
A fs_bytes vector of file sizes.
See also
Other file functions:
download_file()
Examples
library(fs)
library(readr)
files <- c("file1.txt", "file2.txt", "file3.txt")
dir <- tempfile("dir")
dir.create(dir)
for (i in files) {
letters |>
rep(sample(1000:10000, 1)) |>
write_lines(file.path(dir, i))
}
urls <- c(
paste0(
"https://geodata.ucdavis.edu/climate/worldclim/2_1/base/",
"wc2.1_2.5m_tavg.zip"
),
paste0(
"https://geodata.ucdavis.edu/climate/worldclim/2_1/base/",
"wc2.1_10m_prec.zip"
)
)
c(urls, path(dir, files)) |> get_file_size()
#> 422.69M 6.92M 221.96K 151.33K 154.68K
