This tutorial shows how to download any set of files from Synapse using their Synapse IDs. Rather than syncing an entire project or folder, this approach lets you target exactly the files you need and download them concurrently — even directing each file to a different local directory.
In this tutorial you will:
Create a named vector that maps each Synapse ID to the local path where that file should be saved. Files can be directed to different directories as needed.
library(synapser)
synLogin()
# A mapping of Synapse IDs to the local directory each file should be downloaded to.
# Files can be directed to different directories as needed.
SYN_IDS_AND_PATHS <- c(
"syn60584250" = "~/temp/subdir1",
"syn60584256" = "~/temp/subdir1",
"syn60584248" = "~/temp/subdir1",
"syn60584252" = "~/temp/subdir1",
"syn60584258" = "~/temp/subdir1",
"syn60584260" = "~/temp/subdir1",
"syn60584257" = "~/temp/subdir1",
"syn60584251" = "~/temp/subdir1",
"syn60584253" = "~/temp/subdir1",
"syn60584390" = "~/temp/subdir1",
"syn60584405" = "~/temp/subdir2",
"syn60584400" = "~/temp/subdir3"
)Loop over the mapping and use synGet() with
FileOptions(download_location = ...) to download each file
to its mapped directory.
results <- list()
for (syn_id in names(SYN_IDS_AND_PATHS)) {
results[[syn_id]] <- synGet(
syn_id,
file_options = FileOptions(download_location = SYN_IDS_AND_PATHS[[syn_id]])
)
}
print(sprintf("Retrieved %d files", length(results)))After all downloads finish you’ll see output like:
[1] "Retrieved 12 files"