MarkEdmondson1234 / googleAuthR

Google API Client Library for R. Easy authentication and help to build Google API R libraries with OAuth2. Shiny compatible.
https://code.markedmondson.me/googleAuthR
Other
175 stars 54 forks source link

gar_setup_check_session fails when .Renviron doesn't exist #214

Closed jsocolar closed 2 years ago

jsocolar commented 2 years ago

What goes wrong

If I don't have an .Renviron file, gar_setup_check_session() errors with

Error in if (file.exists(local_file)) { : argument is of length zero

EDIT: I'm seeing this error not because I don't have an .Renviron file but rather because I don't have an active Rstudio project (though I am using R via RStudio).

Why it goes wrong

local_file <- file.path(rstudioapi::getActiveProject(), ".Renviron") returns character(0). Thus file.exists(local_file) returns logical(0).

Suggested fix

Change if (file.exists(local_file)) to if (isTRUE(file.exists(local_file))) For example:

local_file <- file.path(rstudioapi::getActiveProject(), ".Renviron")
if(file.exists(local_file)){print("it worked")}else{print("it also worked")}
if(isTRUE(file.exists(local_file))){print("it worked")}else{print("it also worked")}

Session Info

> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS  10.16

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] googleAuthR_1.4.0         googleCloudStorageR_0.6.0

loaded via a namespace (and not attached):
 [1] rstudioapi_0.13  magrittr_2.0.1   R6_2.5.1         rlang_0.4.12     fastmap_1.1.0    fansi_0.5.0      bigQueryR_0.5.0  httr_1.4.2      
 [9] tools_4.0.2      utf8_1.2.2       cli_3.1.0        askpass_1.1      ellipsis_0.3.2   openssl_1.4.5    yaml_2.2.1       assertthat_0.2.1
[17] digest_0.6.28    tibble_3.1.6     gargle_1.2.0     lifecycle_1.0.1  crayon_1.4.2     zip_2.2.0        vctrs_0.3.8      fs_1.5.0        
[25] curl_4.3.2       memoise_2.0.1    glue_1.5.0       cachem_1.0.6     pillar_1.6.4     compiler_4.0.2   jsonlite_1.7.2   pkgconfig_2.0.3 
MarkEdmondson1234 commented 2 years ago

Ah ha, that was then the problem with this https://github.com/MarkEdmondson1234/googleCloudRunner/issues/120

Thanks for the detective work! Yes if you have a patch to fix feel free to add it, a note to self is to use isTRUE() more.