retrieveDirectory.Rd
Retrieve the path to a registered directory (or its subdirectories), possibly creating a local copy of the directory's contents if the caller is not on the same filesystem.
retrieveDirectory(
path,
url,
cache = NULL,
forceRemote = FALSE,
overwrite = FALSE,
concurrent = 1,
updateDelay = 3600
)
String containing the absolute path to 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 all files in the path
via the REST API and cache them 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.
Integer scalar specifying the number of concurrent downloads. Only used for remote access.
Integer scalar specifying the interval before checking for updates in a cached directory, in seconds. Only used for remote access.
Path to the subdirectory on the caller's filesystem. This is either a path to the registered (sub)directory if it is accessible, or a path to a local cache of the directory's contents otherwise.
During remote access, this function exhibits the following behavior:
It will only check for updates to the directory contents after updateDelay
seconds have passed since the previous check.
This avoids unnecessarily frequent requests to the SewerRat API.
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.
Any cached files that are no longer in the remote path
will be deleted from 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.
retrieveDirectory(mydir, url=info$url)
#> [1] "/tmp/Rtmpf63hzc/file1cd1ad152d9"
retrieveDirectory(paste0(mydir, "/diet"), url=info$url, forceRemote=TRUE)
#> [1] "/github/home/.local/share/R/SewerRat/http%3A%2F%2F0.0.0.0%3A5114/LOCAL//tmp/Rtmpf63hzc/file1cd1ad152d9/diet"