bigQueryR
bigQueryR copied to clipboard
Command bqr_download_extract fails in 0.5.0 when downloading from extract job that produced multiple files
Whenever I run the bqr_download_extract command in 0.5.0, I get the following output:
> bqr_download_extract(bqr_get_job(jobId=job_extract,projectId=projectId))
Multiple files to download.
ℹ 2022-05-24 14:09:18 > Request Status Code: 404
Error in `abort_http()`:
! http_404 Unspecified error
Run `rlang::last_error()` to see where the error occurred.
✖ Downloading 1 ... failed
Looking at the traceback and the log, the issue seems to be that the bqr_download_extract command is trying to download a file named "1" rather than a file with the appropriate name.
Looking through the code, this line seems to be the culprit:
if(length(objectnames) > 1){
message("Multiple files to download.")
filename <- paste0(as.character(1:length(objectnames),"_",filename))
}
In cases where there are multiple files (length of object names > 1), then this is assigning the filename to equal a list of numerical strings the length of objectnames. In the case of my machines, if there are three files that it is looking to download, 1:length(objectnames) produces a list [1, 2, 3] and as.character transforms this list to "1" "2" "3". This is why the error messages mentions failing to find file 1. When I replace the logic to set filename equal to objectnames instead of paste0(as.character(1:length(objectnames),"_",filename)), the code works as expected.
Let me know if you need more information to troubleshoot. I haven't used R in a while so I might have missed something obvious, although this error has occurred on multiple machines that members of my team have used.
Thank you it looks like your analysis is correct - do you have a likely fix I can start from?
If you delete the filename <- paste0(as.character(1:length(objectnames),"_",filename)) command and replace with filename <- objectnames, the command worked as I expected. (You may not even need that line because several lines up the same operation is performed, but I haven't tested all the possible edge cases.