I am trying to download a .tif file from my Google Drive folder (which is exported to it via Google Earth Engine), using the googledrive library. However, when calling the map
function, I get the following error:
Error: 'file' identifies more than one Drive file.
I have already managed to download other .tif files with this code, which worked without any error. Why do I get this error, and how do I resolve it? As you can see in the Drive folder (it's public), the folder contains only one file, so why does 'file' identify more than one Drive file?
Code:
library(googledrive)
library(purrr)
## Store the URL to the folder
folder_url <- "https://drive.google.com/drive/folders/1Qdp0GN7_BZoU70OrpbEL-vIBBxBa1_Db"
## Identify this folder on Google Drive
## let googledrive know this is a file ID or URL, as opposed to file name
folder <- drive_get(as_id(folder_url))
## Identify files in the folder
files <- drive_ls(folder, pattern = "*.tif")
# Download all files in folder
map(files$name, overwrite = T, drive_download)
Files: list
returns you by default an arrayEven if the results contain only one file, or no files at all - it will still be an array.
All you need to do is to retrieve the first (0
) element of this array. You can verify it by testing with the Try this API.
I expect the correct syntax in R
to be something like
files[0]$name
to retrieve the name of the first (even if it is the only) file.
Also: You should implement some condition statement to verify that the list of files is not empty before you retrieve the file name.