PMassicotte/gtrendsR

Error in start_top:end_top : NA/NaN argument

shrikant2002 opened this issue · 16 comments

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

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

start_top <- which(grepl("TOP", res))[1]

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.

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

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

@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.

@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")

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)

I installed gtrendsR with this command

if (!require("devtools")) install.packages("devtools")
devtools::install_github("PMassicotte/gtrendsR")

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

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

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"

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

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)

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.