PMassicotte / gtrendsR

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

Error in start_top:end_top : NA/NaN argument #418

Closed shrikant2002 closed 2 years ago

shrikant2002 commented 2 years ago

I updated to 1.5.1 but getting error "Error in start_top:end_top : NA/NaN argument"

here is the reproducible example which throws an error "Error in start_top:end_top : NA/NaN argument" gtrends("Bungie Inc",time="now 1-d", gprop="youtube")

on gtrends webpage there seems no data at all https://trends.google.com/trends/explore?date=now%201-d&gprop=youtube&q=Bungie%20Inc

PMassicotte commented 2 years ago

You do not need to post the same error at multiple places. Please provide a reproducible example.

PMassicotte commented 2 years ago

https://github.com/PMassicotte/gtrendsR/blob/9ddfe46c9d8b9da4d86e4d4a62dd5461634e2a73/R/related_topics.R#L59

The problem come when there are no RISING trend. For example, there is one with "NHL":

> res <- gtrends("NHL", time = "now 1-H")
Called from: eval(expr, p)
Browse[1]> n
debug at /media/work/r_packages/gtrendsr/R/related_topics.R#59: start_top <- which(grepl("TOP", res))[1]
Browse[2]> res
 [1] "Category: All categories"                                 
 [2] "\"NHL: (5/23/22, 5:29 PM - 5/23/22, 6:29 PM, Worldwide)\""
 [3] ""                                                         
 [4] "TOP"                                                      
 [5] "National Hockey League,100"                               
 [6] "Stanley Cup Playoffs,23"                                  
 [7] "NBA,10"                                                   
 [8] "MLB,6"                                                    
 [9] "2021–22 NHL season,4"                                     
[10] "2021 Stanley Cup playoffs,3"                              
[11] "2020–21 NHL season,3"                                     
[12] "Ice hockey,2"                                             
[13] "Standings,2"                                              
[14] "Bracket,2"                                                
[15] "Team,2"                                                   
[16] "2020 Stanley Cup playoffs,2"                              
[17] "Player,1"                                                 
[18] "Draft,1"                                                  
[19] "Playoffs,1"                                               
[20] "Edmonton Oilers,1"                                        
[21] "NHL Entry Draft,1"                                        
[22] "2019–20 NHL season,1"                                     
[23] "Statistics,1"                                             
[24] "National Football League Playoffs,1"                      
[25] "NFL,1"                                                    
[26] "Tampa Bay Lightning,1"                                    
[27] "2021–22 NFL playoffs,1"                                   
[28] "The NBA Finals,1"                                         
[29] ""                                                         
[30] "RISING"                                                   
[31] "Danes,+500%"                                              
[32] "Multiple listing service,+170%"                           
[33] "Franchising,+150%"                                        
[34] "CBC News,+130%"                                           
[35] "International Ice Hockey Federation,+80%"                 
[36] "Jordan Binnington,+80%"                                   
[37] "Stanley Cup Finals,+70%"                                  
[38] "Brayden Point,+60%"                                       
[39] "NHL Stenden University of Applied Sciences,+60%"          
[40] ""                                                         
[41] "" 

Sometimes, there are no RISING and this cause problems.

shrikant2002 commented 2 years ago

here is the reproducible example which throws an error "Error in start_top:end_top : NA/NaN argument" gtrends("Bungie Inc",time="now 1-d", gprop="youtube")

on gtrends webpage there seems no data at all https://trends.google.com/trends/explore?date=now%201-d&gprop=youtube&q=Bungie%20Inc

PMassicotte commented 2 years ago

Should be fixed with https://github.com/PMassicotte/gtrendsR/tree/fix-no-rising-trends

shrikant2002 commented 2 years ago

I am getting the same issue for some keywords in the latest dev release

eddelbuettel commented 2 years ago

@shrikant2002 If you want help you have to show the actual query in other words make this reproducible. We cannot read your mind from a distance. Or even from up close.

See for example How to create a Minimal, Reproducible Example on to effectively communicate this.

shrikant2002 commented 2 years ago

@eddelbuettel Here it is below code produce error "Error in start_top:end_top : NA/NaN argument"

library(gtrendsR)
gtrends("USB",time="now 1-d", gprop="youtube")
PMassicotte commented 2 years ago

Works fine on my side using the branch I pointed out:

library(gtrendsR)

plot(gtrends("USB",time="now 1-d", gprop="youtube"))

Created on 2022-05-25 by the reprex package (v2.0.1)

shrikant2002 commented 2 years ago

I installed gtrendsR with this command

if (!require("devtools")) install.packages("devtools")
devtools::install_github("PMassicotte/gtrendsR")
PMassicotte commented 2 years ago

This is the main/master branch. Not https://github.com/PMassicotte/gtrendsR/tree/fix-no-rising-trends

shrikant2002 commented 2 years ago

I tried installing like this

if (!require("devtools")) install.packages("devtools")
devtools::install_github("https://github.com/PMassicotte/gtrendsR/tree/fix-no-rising-trends")

but still got the same error

PMassicotte commented 2 years ago

Can not help furthermore at this time since I can not replicate your problem.

shrikant2002 commented 2 years ago
library(devtools)
install_github("https://github.com/PMassicotte/gtrendsR/tree/fix-no-rising-trends", force = TRUE)

This should have fixed this issue but after updating it I am getting error "widget$status_code == 200 is not TRUE"

shrikant2002 commented 2 years ago

pls try this query using this branch

library(devtools)
install_github("https://github.com/PMassicotte/gtrendsR/tree/fix-no-rising-trends", force = TRUE)
library(gtrendsR)
gtrends("Tau Herculids",time="now 1-d",
        gprop="youtube")

it produces the same error

Error in start_top:end_top : NA/NaN argument

on google trends page it has no rising related queries and that might be the problem https://trends.google.com/trends/explore?date=now%201-d&gprop=youtube&q=Tau%20Herculids

PMassicotte commented 2 years ago

It is working here.

library(gtrendsR)

plot(gtrends("Tau Herculids",
  time = "now 1-d",
  gprop = "youtube"
))

Created on 2022-05-26 by the reprex package (v2.0.1)

eddelbuettel commented 2 years ago

Same here, on the branch and having freshly installed from it (not shown below but a simple R CMD INSTALL . variant):

edd@rob:~/git/gtrendsr(fix-no-rising-trends)$ R -q
> getwd()
[1] "/home/edd/git/gtrendsr"
> system("git rev-parse --abbrev-ref HEAD")
fix-no-rising-trends
> library(gtrendsR)
> plot(gtrends("Tau Herculids", time = "now 1-d", gprop = "youtube"))   # plot window not shown here
> object.size(gtrends("Tau Herculids", time = "now 1-d", gprop = "youtube"))
80312 bytes
> 

Maybe @shrikant2002 has an issue with devtools and installing from git, maybe it is his account handle -- we do not know and cannot reproduce. Locking this as resolved was appropriate.