I'm trying to automatically run an r script to download a private Google Sheet every hour. It always works fine when I'm interactively using R. It also works fine during the first hour after I automate the script with launchd
.
It stops working an hour after I start automating it with launchd
. I think the problem is that after one hour the access token changes, and the non-interactive version isn’t waiting for the auto refreshing of the OAuth token. Here is the error that I get from the error report:
Auto-refreshing stale OAuth token. Error in gzfile(file, mode) : cannot open the connection Calls: gs_auth ... -> -> cache_token -> saveRDS -> gzfile In addition: Warning message: In gzfile(file, mode) : cannot open compressed file '.httr-oauth', probable reason 'Permission denied' Execution halted
I'm using Jenny Bryan's googlesheets package. Here is the code that I initially use to register the sheet, and then save the oAuth token:
gToken <- gs_auth() # Run this the first time to get the oAuth information
saveRDS(gToken, "/Users/…/gToken.rds") # Save the oAuth information for non-interactive use
I then use the following script in the file that I automate with launchd
:
gs_auth(token = "/Users/…/gToken.rds")
How can I avoid this error when running the script automatically with launchd
?