R/download.R
listGoogleDriveFolder.RdA remap-aware alternative to googledrive::drive_ls() for listing a Google
Drive folder's files. When the folder id is in the reproducible.urlRemap
manifest as a directory remap (a type = "dir" row; see makeUrlRemap()),
the files are enumerated from the public bucket listing with no Google
authentication. Otherwise it falls back to googledrive::drive_ls() (which
authenticates as usual). It is meant as a near drop-in for the common
as.data.table(drive_ls(url)) pattern: filter the returned names, then pass
the corresponding urls to prepInputs().
listGoogleDriveFolder(
url,
pattern = NULL,
verbose = getOption("reproducible.verbose", 1)
)A data.table with columns name (file name), id (the Google Drive
file id when listed from Drive; NA on the mirror path), and url – a URL
to hand to prepInputs(): the public mirror URL when remapped, otherwise the
Drive file URL. A 0-row table when the folder is empty/unreachable.
makeUrlRemap() for the directory-remap manifest;
buckethost::makeMirrorManifest(directories = TRUE) to build one.
# A directory-remap manifest maps a Drive *folder* id to a bucket prefix-listing
# URL; build it with buckethost::makeMirrorManifest(directories = TRUE), or by
# hand (a `type = "dir"` row):
manifest <- data.frame(
filename = "2020",
url = paste0("https://object-arbutus.cloud.computecanada.ca/",
"predictiveecology/?prefix=SCANFI_v2/2020/&delimiter=/"),
id = "15T4HIFeqzwp0TuOuxmYoexuXdLFnCZBi",
type = "dir"
)
remap <- makeUrlRemap(manifest) # the "dir" row populates the folder-listing map
# Then, with `options(reproducible.urlRemap = manifest)` set, a call such as
# files <- listGoogleDriveFolder(
# "https://drive.google.com/drive/folders/15T4HIFeqzwp0TuOuxmYoexuXdLFnCZBi")
# lists that folder from the public mirror with no drive_auth(), returning
# name/id/url columns to feed to prepInputs(); without a manifest it falls back
# to googledrive::drive_ls() (which authenticates as usual).