retrieveFile.Rd
Retrieve the path to a single file in a registered directory. This will call the REST API to obtain and cache a copy of the file if the caller is not on the same filesystem.
retrieveFile(path, url, cache = NULL, forceRemote = FALSE, overwrite = FALSE)
String containing the absolute path to a file in a registered directory.
String containing the URL to the SewerRat REST API.
String containing a path to a cache directory.
If NULL
, an appropriate location is automatically chosen.
Only used for remote access.
Logical scalar indicating whether to force remote access.
This will download path
via the REST API and cache it locally,
even if path
is on the same filesystem as the caller.
Logical scalar indicating whether to overwrite the existing cache. Only used for remote access.
String containing the path to the file on the caller's filesystem.
During remote access, if a file in path
has already been locally cached, retrieveDirectory
will be automatically check the SewerRat API for updates.
Any updates on the remote will cause the new file to be re-downloaded to the cache.
info <- startSewerRat()
# Mocking up a directory of stuff to query.
mydir <- tempfile()
dir.create(mydir)
write(file=file.path(mydir, "foo"), '{ "first": "Aaron", "last": "Lun" }')
dir.create(file.path(mydir, "diet"))
write(file=file.path(mydir, "diet", "bar"),
'{ "meal": "lunch", "ingredients": "water" }')
# Registering it:
register(mydir, "metadata.json", url=info$url)
# Fetching it, either directly or via the API.
retrieveFile(paste0(mydir, "/foo"), url=info$url)
#> [1] "/tmp/Rtmpf63hzc/file1cd597b67c/foo"
retrieveFile(paste0(mydir, "/diet/bar"), url=info$url, forceRemote=TRUE)
#> [1] "/github/home/.local/share/R/SewerRat/http%3A%2F%2F0.0.0.0%3A5114/LOCAL//tmp/Rtmpf63hzc/file1cd597b67c/diet/bar"