简体   繁体   English

gtrendsR查询的问题

[英]Issues with gtrendsR queries

I am receiving two errors on gTrendsR searches. 我在gTrendsR搜索中收到两个错误。 I attempted to use the package with both the CRAN download and devel version from https://github.com/PMassicotte/gtrendsR . 我尝试使用包含CRAN下载和开发版本的软件包来自https://github.com/PMassicotte/gtrendsR

library(gtrendsR)
gconnect(usr, psw, verbose=TRUE)
#Google login successful!
sport_trend <- gtrends(c("nhl", "nba", "nfl"))
#Error in names(trend) <- make.names(paste(kw, geo)) : 
#  'names' attribute [3] must be the same length as the vector [0]

gtrends("Kim Kardashian")
#Error: Not enough search volume. Please change your search terms.

I have tried many search terms to no avail. 我尝试了很多搜索条件无济于事。 The function in question appears to be .processResults : 有问题的函数似乎是.processResults

  kw <- trimws(unlist(strsplit(queryparams[1], ","), use.names = FALSE))
  geo <- trimws(unlist(strsplit(queryparams[3], ","), use.names = FALSE))
  names(trend) <- make.names(paste(kw, geo))

These expressions do not appear to rely on the search results but on the query itself. 这些表达式似乎不依赖于搜索结果,而是依赖于查询本身。 The second error stems from: 第二个错误源于:

if (length(vec) < 2) {
    stop("Not enough search volume. Please change your search terms.",
         call. = FALSE)
  }

The variable vec gets its value from getForm which I could not find documentation for. 变量vecgetForm获取其值,我找不到文档。 I have tried to specify the query items but that did not work either. 我试图指定查询项,但这也不起作用。 Restarting the R session also did not resolve the issue. 重新启动R会话也无法解决问题。

The session information: 会话信息:

sessionInfo()
# R version 3.2.3 (2015-12-10)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 7 x64 (build 7601) Service Pack 1
# 
# locale:
#   [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
# [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
# [5] LC_TIME=English_United States.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] zoo_1.7-12       colorspace_1.2-6 scales_0.4.0     googleVis_0.5.10 plyr_1.8.3      
# [6] tools_3.2.3      gtable_0.2.0     RCurl_1.95-4.8   Rcpp_0.12.3      ggplot2_2.1.0   
# [11] RJSONIO_1.3-0    grid_3.2.3       munsell_0.4.3    bitops_1.0-6     lattice_0.20-33

The package authors had to do a full rewrite due to Google API changes. 由于Google API的更改,软件包作者必须完全重写。 Get the unreleased gtrendsR 2.0.0 code here: 在这里获取未发布的gtrendsR 2.0.0代码:

devtools::install_github('PMassicotte/gtrendsR')

library(gtrendsR)
# do not need to log in anymore
# syntax change!
gt.us <- gtrends("USA", geo="US", time = "2004-01-01 2004-01-30")

I was having the same problem. 我遇到了同样的问题。 For some reason changing my code like below helped. 出于某种原因,改变我的代码如下所示。 Hopefully you can figure out why. 希望你能弄明白为什么。 I'm a noob. 我是个菜鸟。

> styles <- gtrends(query=c("Pixie Pant", "Yoga Pants", "Jeans"))
# Error in names(trend) <- make.names(paste(kw, geo)) : 
# 'names' attribute [3] must be the same length as the vector [2]
> commodities2 <- gtrends(c("Oil prices", "mortgage rates"), res="7d", geo= "US")
> styles <- gtrends(c("Pixie Pant", "Yoga Pants", "Jeans"))
# Error in names(trend) <- make.names(paste(kw, geo)) : 
#  'names' attribute [3] must be the same length as the vector [2]
> styles <- gtrends(c("Pixie Pant", "Yoga Pants", "Jeans"), res="7d", geo= "US")
> plot(styles)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM