PMassicotte / gtrendsR

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

Error in read.table #177

Closed tiernanmartin closed 7 years ago

tiernanmartin commented 7 years ago

I have encountered the following error with a wide variety of keywords:

library(gtrendsR)

data <- gtrends(keyword = "moonlight showtimes")
#> Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

Here's the traceback:

> traceback()
#> 7: stop("duplicate 'row.names' are not allowed")
#> 6: read.table(file = file, header = header, sep = sep, quote = quote, 
#>        dec = dec, fill = fill, comment.char = comment.char, ...)
#> 5: read.csv(textConnection(res[(start + 1):(end - 1)]))
#> 4: FUN(X[[i]], ...)
#> 3: lapply(i, create_related_topics_payload, widget = widget)
#> 2: related_topics(widget, comparison_item)
#> 1: gtrends(keyword = "moonlight showtimes")

As you can see here, the issue is not that there isn't any data to be collected.

PMassicotte commented 7 years ago

Will be merged soon to master.

library(gtrendsR)

data <- gtrends(keyword = "moonlight showtimes")

plot(data)

tiernanmartin commented 7 years ago

After installing the latest dev version, I am still running into this error:

data <- gtrends(keyword = "moonlight showtimes",geo = 'US')
#> Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
#>   duplicate 'row.names' are not allowed
eddelbuettel commented 7 years ago

Then you are doing something wrong, or have a "unusual" R installation, or ...

edd@max:~/git/gtrendsr(master)$ git pu
Fetching origin
Already up-to-date.
edd@max:~/git/gtrendsr(master)$ R CMD INSTALL .
* installing to library ‘/usr/local/lib/R/site-library’
* installing *source* package ‘gtrendsR’ ...
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (gtrendsR)
edd@max:~/git/gtrendsr(master)$ r -lgtrendsR -e'print(str(gtrends(keyword = "moonlight showtimes",geo = "US")))'
List of 6
 $ interest_over_time:'data.frame':     261 obs. of  5 variables:
  ..$ date   : POSIXct[1:261], format: "2012-03-18" "2012-03-25" "2012-04-01" "2012-04-08" ...
  ..$ hits   : int [1:261] 0 0 0 1 0 0 0 0 1 3 ...
  ..$ keyword: chr [1:261] "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" ...
  ..$ geo    : chr [1:261] "US" "US" "US" "US" ...
  ..$ gprop  : chr [1:261] "web" "web" "web" "web" ...
 $ interest_by_region:'data.frame':     43 obs. of  5 variables:
  ..$ location: chr [1:43] "District of Columbia" "New York" "California" "Illinois" ...
  ..$ hits    : int [1:43] 100 98 68 64 62 61 59 50 50 48 ...
  ..$ keyword : chr [1:43] "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" ...
  ..$ geo     : chr [1:43] "US" "US" "US" "US" ...
  ..$ gprop   : chr [1:43] "web" "web" "web" "web" ...
 $ interest_by_dma   :'data.frame':     73 obs. of  5 variables:
  ..$ location: chr [1:73] "San Francisco-Oakland-San Jose CA" "Baton Rouge LA" "Tucson (Sierra Vista) AZ" "New York NY" ...
  ..$ hits    : int [1:73] 100 88 87 85 84 82 75 73 71 71 ...
  ..$ keyword : chr [1:73] "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" ...
  ..$ geo     : chr [1:73] "US" "US" "US" "US" ...
  ..$ gprop   : chr [1:73] "web" "web" "web" "web" ...
 $ interest_by_city  :'data.frame':     4 obs. of  5 variables:
  ..$ location: chr [1:4] "New York" "Washington" "Los Angeles" "Chicago"
  ..$ hits    : int [1:4] 100 74 73 61
  ..$ keyword : chr [1:4] "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" "moonlight showtimes"
  ..$ geo     : chr [1:4] "US" "US" "US" "US"
  ..$ gprop   : chr [1:4] "web" "web" "web" "web"
 $ related_topics    :'data.frame':     50 obs. of  5 variables:
  ..$ subject       : chr [1:50] "100" "95" "40" "25" ...
  ..$ related_topics: chr [1:50] "top" "top" "top" "top" ...
  ..$ value         : chr [1:50] "Film" "Moonlight" "Movie theater" "Magic in the Moonlight" ...
  ..$ geo           : chr [1:50] "US" "US" "US" "US" ...
  ..$ keyword       : chr [1:50] "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" ...
 $ related_queries   :'data.frame':     27 obs. of  5 variables:
  ..$ subject        : chr [1:27] "movie showtimes" "moonlight movie showtimes" "moonlight movie" "movies" ...
  ..$ related_queries: chr [1:27] "top" "top" "top" "top" ...
  ..$ value          : chr [1:27] "100" "100" "95" "30" ...
  ..$ geo            : chr [1:27] "US" "US" "US" "US" ...
  ..$ keyword        : chr [1:27] "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" "moonlight showtimes" ...
 - attr(*, "class")= chr [1:2] "gtrends" "list"
NULL
edd@max:~/git/gtrendsr(master)$ 
tiernanmartin commented 7 years ago

@eddelbuettel correct - uninstalling and re-installing the package resolved the issue 👍

tiernanmartin commented 7 years ago

Actually, even with the fresh install I'm still running into this problem:


library(gtrendsR)

# Succeeds
data_dogs <- gtrends(keyword = "dogs", geo = "US")

#Fails
data_showtimes <- gtrends(keyword = "moonlight showtimes", geo = "US")
#> Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

data_showtimes_web <- gtrends(keyword = "moonlight showtimes", geo = "US", gprop = "web")
#> Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

data_showtimes_lastyr <- gtrends(keyword = "moonlight showtimes", geo = "US", 
  time = "today 12-m", gprop = "web")
#> Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed

Oddly, I have experienced inconsistent success with the gtrends(keyword = "moonlight showtimes", geo = "US") command... I haven't observed similar behavior in other packages loaded with this R installation, but that doesn't mean much.

If other gtrendsR users are experiencing this behavior I hope they will join this conversation.


EDIT I waited five minutes before re-running the same script and got different results... what could be causing this inconsistency?


library(gtrendsR)

data_dogs <- gtrends(keyword = "dogs", geo = "US")

data_showtimes <- gtrends(keyword = "moonlight showtimes", geo = "US")

data_showtimes_web <- gtrends(keyword = "moonlight showtimes", geo = "US", gprop = "web")

data_showtimes_lastyr <- gtrends(keyword = "moonlight showtimes", geo = "US", 
  time = "today 12-m", gprop = "web")
#> Error in read.table(file = file, header = header, sep = sep, quote = quote, : duplicate 'row.names' are not allowed
PMassicotte commented 7 years ago

Just fixed this. Reinstall the dev version.

PMassicotte commented 7 years ago

library(gtrendsR)

res <- gtrends(keyword = "moonlight showtimes", geo = "US", time = "today 12-m", 
  gprop = "web")

lapply(res, head)
#> $interest_over_time
#>         date hits             keyword geo gprop
#> 1 2016-03-20    0 moonlight showtimes  US   web
#> 2 2016-03-27    0 moonlight showtimes  US   web
#> 3 2016-04-03    0 moonlight showtimes  US   web
#> 4 2016-04-10    0 moonlight showtimes  US   web
#> 5 2016-04-17    0 moonlight showtimes  US   web
#> 6 2016-04-24    0 moonlight showtimes  US   web
#> 
#> $interest_by_region
#>               location hits             keyword geo gprop
#> 1 District of Columbia  100 moonlight showtimes  US   web
#> 2             New York  100 moonlight showtimes  US   web
#> 3           California   77 moonlight showtimes  US   web
#> 4              Vermont   76 moonlight showtimes  US   web
#> 5           Washington   70 moonlight showtimes  US   web
#> 6        Massachusetts   69 moonlight showtimes  US   web
#> 
#> $interest_by_dma
#>                                       location hits             keyword
#> 1                          Monterey-Salinas CA  100 moonlight showtimes
#> 2 Santa Barbara-Santa Maria-San Luis Obispo CA   90 moonlight showtimes
#> 3                                    Eugene OR   59 moonlight showtimes
#> 4                      Hartford & New Haven CT   58 moonlight showtimes
#> 5            San Francisco-Oakland-San Jose CA   56 moonlight showtimes
#> 6                                  New York NY   53 moonlight showtimes
#>   geo gprop
#> 1  US   web
#> 2  US   web
#> 3  US   web
#> 4  US   web
#> 5  US   web
#> 6  US   web
#> 
#> $interest_by_city
#>      location hits             keyword geo gprop
#> 1    New York  100 moonlight showtimes  US   web
#> 2 Los Angeles   82 moonlight showtimes  US   web
#> 3     Chicago   60 moonlight showtimes  US   web
#> 
#> $related_topics
#>   subject related_topics                 value geo             keyword
#> 1     100            top             Moonlight  US moonlight showtimes
#> 2     100            top                  Film  US moonlight showtimes
#> 3      35            top         Movie theater  US moonlight showtimes
#> 4      25            top             Moonlight  US moonlight showtimes
#> 5      15            top          AMC Theatres  US moonlight showtimes
#> 6      15            top Manchester-by-the-Sea  US moonlight showtimes
#> 
#> $related_queries
#>                       subject related_queries value geo
#> 1             movie showtimes             top   100  US
#> 2             moonlight movie             top   100  US
#> 3   moonlight movie showtimes             top    95  US
#> 4                      movies             top    30  US
#> 5 moonlight showtimes near me             top    20  US
#> 6     moonlight nyc showtimes             top    15  US
#>               keyword
#> 1 moonlight showtimes
#> 2 moonlight showtimes
#> 3 moonlight showtimes
#> 4 moonlight showtimes
#> 5 moonlight showtimes
#> 6 moonlight showtimes