2

I am trying to use the gtrends package but I keep getting the following error:

dp <- gtrends("Donald Drumpf", res="7d")
Error in .processResults(resultsText, queryparams) : 
  could not find function "trimws"

Here is the full code:

library(gtrendsR)
dp <- gtrends("Donald Drumpf", res="7d")
plot(dp) + ggplot2::ggtitle("The Drumpf") + ggplot2::theme(legend.position="none")

You might have to use the gconnect() function to get it to work.

Thanks!

EDIT: Here is the sessionInfo() output:

R version 3.1.3 (2015-03-09)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 8 x64 (build 9200)

locale:
[1] LC_COLLATE=Portuguese_Brazil.1252  LC_CTYPE=Portuguese_Brazil.1252   
[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.1252    

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] bitops_1.0-6     colorspace_1.2-4 ggplot2_2.0.0    googleVis_0.5.10
 [5] grid_3.1.3       gtable_0.1.2     lattice_0.20-30  munsell_0.4.2   
 [9] plyr_1.8.3       Rcpp_0.11.4      RCurl_1.95-4.5   RJSONIO_1.3-0   
[13] scales_0.3.0     tools_3.1.3      zoo_1.7-11  
user191919
  • 724
  • 1
  • 9
  • 27
  • I had issues with the package also. Perhaps official issue reports may be necessary. [Issues with gtrendsR queries](http://stackoverflow.com/questions/35878239/issues-with-gtrendsr-queries) – Pierre L Mar 11 '16 at 14:19
  • That's strange, it worked fine for me. Can you please include `sessionInfo()` in your question? – nrussell Mar 11 '16 at 14:21
  • 1
    I suspect it is the same function that I had issues with `.processResults`. Code here at github https://github.com/PMassicotte/gtrendsR/blob/master/R/gtrends.R#L500 – Pierre L Mar 11 '16 at 14:23
  • 2
    It looks like `trimws` [was added](https://cran.r-project.org/src/base/NEWS) in R version 3.2.0. Maybe the package could provide that function for users running R < 3.2.0 since its [definition](https://gist.github.com/nathan-russell/6b3a630f52da8eb52463) is pretty simple. – nrussell Mar 11 '16 at 14:26
  • @nrussell put it as answer – jangorecki Mar 12 '16 at 19:19
  • It was just a matter of updating my `R` version. Should I post ir as an answer? – user191919 Mar 15 '16 at 17:25

2 Answers2

1

Just for the sake of completeness. I tested it with different R versions (below 3.2 and beyond). R below 3.2 is definitely the reason it does not work. trimws is only available in more recent versions. Update R and it'll work.

Be aware of the fact that google might block new machines in the beginning. But once they're convinced it was you who accessed that account it will just work.

Matt Bannert
  • 27,631
  • 38
  • 141
  • 207
0

It works for me. just need to remove res='7d' dp <- gtrends("Donald Drumpf") plot(dp) + ggplot2::ggtitle("The Drumpf") + ggplot2::theme(legend.position="none") This is the output I have just updated to latest R version 3.4.0 (2017-04-21)Trump Trends

Susan Li
  • 101
  • 1
  • 3