PMassicotte / gtrendsR

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

Error in gtrends function on Windows 10. #95

Closed selesnow closed 7 years ago

selesnow commented 8 years ago

Hi! When i try use gtrends i get error:

sport_trend2 <- gtrends(c("nhl", "nba", "nfl"))

Error in read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'strsplit(vec[2], "\n")[[1]]'

sessionInfo()

R version 3.3.0 (2016-05-03) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows >= 8 x64 (build 9200)

locale: [1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251 LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C
[5] LC_TIME=Russian_Russia.1251

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

other attached packages: [1] devtools_1.11.1 RCurl_1.95-4.8 bitops_1.0-6 gtrendsR_1.3.3

Do you know how fix this?

eddelbuettel commented 8 years ago

That is probably a local issue; your Google access may be limited or something else. There is structural reason Windows 10 would be different.

selesnow commented 8 years ago

maybe you can fix problem after then:

in debug function i get erroe after res <- .processResults(resultsText, queryparams)

Browse[3]> n debug: authenticatePage2 <- getURL("http://www.google.com", curl = ch) Browse[3]> n debug: trendsURL <- "http://www.google.com/trends/trendsReport?" Browse[3]> n debug: pp <- list(q = query, cat = cat, cmpt = cmpt, content = 1, export = 1, date = date, geo = geo) Browse[3]> n debug: resultsText <- getForm(trendsURL, .params = pp, curl = ch) Browse[3]> n debug: if (any(grep("QUOTA", resultsText))) { stop("Reached Google Trends quota limit! Please try again later.") } Browse[3]> n debug: queryparams <- c(query = query, cat = cat, geo = geo, time = format(Sys.time())) Browse[3]> n debug: res <- .processResults(resultsText, queryparams) Browse[3]> n Error in read.table(file = file, header = header, sep = sep, quote = quote, : incomplete final line found by readTableHeader on 'strsplit(vec[2], "\n")[[1]]'

In this step i have this Environment

http://img.netpeak.ua/alsey/146496952879_kiss_370kb.jpg

PMassicotte commented 8 years ago

Probably related to Russian encoding of the returned text.

PMassicotte commented 8 years ago

Please send me the resultsText object returned by the query. This must be related to #71.

selesnow commented 8 years ago

You can download resultText file.

PMassicotte commented 8 years ago

Can you also return queryparams please?

selesnow commented 8 years ago

@PMassicotte you can go link for download queryparams.RData file.

PMassicotte commented 8 years ago

@selesnow As I understand it crashes in .processResults? It is strange because it is working fine if I am using both objects you sent me.

> data <- .processResults(resultsText, queryparams)
> head(data$trend)
       start        end nhl.CA nhl.US
1 2004-01-04 2004-01-10     23      2
2 2004-01-11 2004-01-17     22      2
3 2004-01-18 2004-01-24     22      3
4 2004-01-25 2004-01-31     19      2
5 2004-02-01 2004-02-07     21      2
6 2004-02-08 2004-02-14     21      3

I suspect the issue is related to the Russian local encoding you are using based on your sessionInfo().

PMassicotte commented 7 years ago

@selesnow do you still have problems with this?

selesnow commented 7 years ago

@PMassicotte Hi, i will chek this today.

PMassicotte commented 7 years ago

@selesnow

Can new try this?

First install the new upcoming version

# devtools::install_github('PMassicotte/gtrendsR', ref = 'new-api')

Note that you do not need to log in anymore.

library(gtrendsR)

res <- gtrends(c("nhl", "nba", "nfl"))

head(res$interest_over_time)
#>         date hits keyword   geo
#> 1 2012-02-19    8     nhl world
#> 2 2012-02-26    8     nhl world
#> 3 2012-03-04    7     nhl world
#> 4 2012-03-11    7     nhl world
#> 5 2012-03-18    7     nhl world
#> 6 2012-03-25    7     nhl world
head(res$interest_by_region)
#>             location hits keyword   geo
#> 1        Philippines    0     nhl world
#> 2 Dominican Republic    9     nba world
#> 3          Venezuela   28     nfl world
#> 4             Canada   58     nhl world
#> 5        Puerto Rico    0     nba world
#> 6      United States    8     nfl world

plot(res)

selesnow commented 7 years ago

@PMassicotte

Great, all work, very thanks!!!