Why does the googledrive library in R identifies more than one file with only one file in the Drive folder?

拥有回忆 提交于 2020-12-12 06:13:04

问题


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)

回答1:


Google Drive API's method Files: list returns you by default an array

Even 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.




回答2:


Google Drive allows for multiple files with the exact same name in the same folder. The googledrive library does not accept this and thus will throw an error. However, even after deleting "double" files, the error wasn't solved. It seems that Google Drive also keeps some kind of hidden record/cache of the files, even when there are deleted. Only by deleting the entire folder and recreating it, I was able to solve the error.



来源:https://stackoverflow.com/questions/59896107/why-does-the-googledrive-library-in-r-identifies-more-than-one-file-with-only-on

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!