PMassicotte / gtrendsR

R functions to perform and display Google Trends queries
355 stars 112 forks source link

Package can't load when only Env vars used for user/password #102

Closed MarkEdmondson1234 closed 8 years ago

MarkEdmondson1234 commented 8 years ago

I put similar to below in my home directory .Renviron file:

GOOGLE_USER = "mark@xxxx.com"
GOOGLE_PASSWORD = '1xxxxxxxx'
GOOGLE_AUTOCONNECT = 'TRUE'

(note no options set) I restarted R, and could reach them via Sys.getenv("GOOGLE_USER") etc.

However, when I tried to load the library, I got this:

> library(gtrendsR)
Creating a generic function for ‘toJSON’ from package ‘jsonlite’ in package ‘googleVis’
Error : .onAttach failed in attachNamespace() for 'gtrendsR', details:
  call: if (getOption("google.user") != "") usr <- getOption("google.user")
  error: argument is of length zero
Error: package or namespace load failed for ‘gtrendsR’

When I set the options myself from the environment vars, it works:

options(google.user = Sys.getenv("GOOGLE_USER"))
options(google.password = Sys.getenv("GOOGLE_PASSWORD"))
library(gtrendsR)

The help file seems to indicate you can use either environment or options, and its all working now, but I guess the above is not intended.


R version 3.2.4 (2016-03-10) -- "Very Secure Dishes"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.4.0 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

[Workspace loaded from ~/dev/R/gdelt_brand_monitoring/.RData]

> library(gtrendsR)
Creating a generic function for ‘toJSON’ from package ‘jsonlite’ in package ‘googleVis’
Error : .onAttach failed in attachNamespace() for 'gtrendsR', details:
  call: if (getOption("google.user") != "") usr <- getOption("google.user")
  error: argument is of length zero
Error: package or namespace load failed for ‘gtrendsR’

Restarting R session...

> library(gtrendsR)
Creating a generic function for ‘toJSON’ from package ‘jsonlite’ in package ‘googleVis’
Error : .onAttach failed in attachNamespace() for 'gtrendsR', details:
  call: if (getOption("google.user") != "") usr <- getOption("google.user")
  error: argument is of length zero
Error: package or namespace load failed for ‘gtrendsR’
> options(google.user = Sys.getenv("GOOGLE_USER"))
> options(google.password = Sys.getenv("GOOGLE_PASSWORD"))
> library(gtrendsR)
> gconnect()
> sessionInfo()
R version 3.2.4 (2016-03-10)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.11.3 (El Capitan)

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

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

other attached packages:
[1] gtrendsR_1.3.3

loaded via a namespace (and not attached):
 [1] zoo_1.7-12       colorspace_1.2-6 scales_0.3.0     googleVis_0.6.0  plyr_1.8.3       tools_3.2.4     
 [7] gtable_0.1.2     RCurl_1.95-4.7   Rcpp_0.12.5      ggplot2_2.1.0    grid_3.2.4       jsonlite_1.0    
[13] munsell_0.4.2    bitops_1.0-6     lattice_0.20-33 
PMassicotte commented 8 years ago

@eddelbuettel Do you have an idea?

eddelbuettel commented 8 years ago

Nope.

Any sane operating system (ie not the one from Redmond) sets $HOME. R, just like any sane program in the Unix tradition, then reads dotfiles from $HOME. (It also reads from current directory, see help(Startup) but that is a digression.)

Now, what do I do? I actually (by convention) set this in ~/.Rprofile but mostly ... because I already set other things there The again I just needed some database settings at work for some tests and stuck those into Renviron.site. Also worked. YMMV.

In short it all works for me...

MarkEdmondson1234 commented 8 years ago

this is solved by this https://github.com/PMassicotte/gtrendsR/issues/121

eddelbuettel commented 8 years ago

Good catch, thank you. Should have smelled the bacon when you first reported this.