Closed hongyileoxu closed 1 year ago
I am having the same issue. It will eventually work if I run download_file multiple times, but I can't get it to consistently work on the first few tries.
This is what I'm running:
load_data_file <- function(file_name){
temp_file_path <- tempfile("file_name")
site <- Microsoft365R::get_sharepoint_site("my site")
drive <- site$get_drive("Documents")
folder <- drive$get_item("my dir")
file <- folder$get_item(file_name)
success <- FALSE # Flag to check if download was successful
for(i in 1:5) { # Try to download 3 times
result <- tryCatch({
file$download(overwrite = T, dest = temp_file_path)
success <- TRUE # If we reach this line, download was successful
readxl::read_excel(temp_file_path)
},
error = function(e) {
print(paste("Attempt", i, "failed:", e))
if(i < 5) {
Sys.sleep(3) # Wait for 3 seconds before the next attempt
}
NULL # Return NULL on error
})
if(success) {
return(result) # If successful, exit the loop and return result
}
}
stop("Failed to download the file after 5 attempts.") # If all attempts fail, throw an error
}
Since you can eventually download successfully, this indicates that Microsoft365R is working and the problem is in a lower-level package, most likely curl. I'm not sure what to do about this, but you can ask for help on the Posit/Rstudio forum, or post an issue on the curl repo.
Thank you in advance.
I am very new to this and currently using Rstudio Server to do some data work. I have successfully connect my business Onedrive with Rstudio server and can find see the files in Onedrive. However, when I try to download the file from Onedrive, e.g.
my_onedrive$download_file("SHoF/2021_info.zip", overwrite = T)
, it gives me the following error message:Meanwhile, a file with this name will show up in the directory but cannot be opened and 0 file size.
This issue seems not to link to the file size. I also updated the "curl" packages and the issue did not go away.
Did anyone encounter the same issue? Really appreciated.