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,
  updateDelay = 3600
)

Arguments

path

String containing the absolute path to a file in a registered directory.

url

String containing the URL to the SewerRat REST API.

cache

String containing a path to a cache directory. If NULL, an appropriate location is automatically chosen. Only used for remote access.

forceRemote

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.

overwrite

Logical scalar indicating whether to overwrite the existing cache. Only used for remote access.

updateDelay

Integer scalar specifying the maximum age of a cached file, in seconds. Older files will be automatically checked for updates. Only used for remote access.

Value

String containing the path to the file on the caller's filesystem.

Author

Aaron Lun

Examples

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/RtmpJDU5Vu/file2173bcf4873/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/RtmpJDU5Vu/file2173bcf4873/diet/bar"