MarkEdmondson1234 / searchConsoleR

R interface with Google Search Console API v3, including Search Analytics.
http://code.markedmondson.me/searchConsoleR/
Other
114 stars 41 forks source link

Error: $ operator is invalid for atomic vectors #70

Open mrhfmn opened 3 years ago

mrhfmn commented 3 years ago

What goes wrong

Hi Mark!

I have been using your package for years in the past so thank you SO much for creating it.

Today I tried installing it again and I am running into an error and I wonder where it could come from as it always worked perfectly for me in the past. The Auth is working perfectly.

Steps to reproduce the problem

## Mark Edmondson (http://markedmondson.me)

library(searchConsoleR)
library(googleAuthR)

website <- "XXX"
start <- Sys.Date() - 545
end <- Sys.Date() - 3 

## what to download, choose between data, query, page, device, country
download_dimensions <- c('date','query')

## what type of Google search, choose between 'web', 'video' or 'image'
type <- c('web')

## other options available, check out ?search_analytics in the R console

## Authorize script with Search Console.  
## First time you will need to login to Google,
## but should auto-refresh after that so can be put in 
## Authorize script with an account that has access to website.
scr_auth()

## first time stop here and wait for authorization

## get the search analytics data
data <- search_analytics(siteURL = website, 
                         startDate = start, 
                         endDate = end, 
                         dimensions = download_dimensions, 
                         searchType = type,
                         rowLimit = 25000,
                         walk_data = "byDate")

## do stuff to the data
## combine with Google Analytics, filter, apply other stats etc.

## write a csv to a nice filename
filename <- paste("search_analytics",
                  Sys.Date(),
                  paste(downloadmensions, collapse = "",sep=""),
                  type,".csv",sep="-")

write.csv(data, filename)

Expected output

When running the script I should get the normal output

Actual output

Selection: 1
Fetching search analytics for url: XXX dates: 2019-12-31 2021-06-25 dimensions: date query dimensionFilterExp:  searchType: web aggregationType: auto
Batching data via method: byDate
Will fetch up to 25000 rows per day
Error: $ operator is invalid for atomic vectors

Session Info

sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

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

other attached packages:
[1] googleAuthR_1.4.0    searchConsoleR_0.4.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.6       rstudioapi_0.13  magrittr_2.0.1   rappdirs_0.3.3   R6_2.5.0         rlang_0.4.11    
 [7] fastmap_1.1.0    fansi_0.5.0      httr_1.4.2       tools_4.1.0      utf8_1.2.1       cli_2.5.0       
[13] withr_2.4.2      askpass_1.1      ellipsis_0.3.2   openssl_1.4.4    assertthat_0.2.1 digest_0.6.27   
[19] tibble_3.1.2     gargle_1.1.0     lifecycle_1.0.0  crayon_1.4.1     later_1.2.0      promises_1.2.0.1
[25] vctrs_0.3.8      fs_1.5.0         curl_4.3.1       memoise_2.0.0    glue_1.4.2       cachem_1.0.5    
[31] compiler_4.1.0   pillar_1.6.1     jsonlite_1.7.2   httpuv_1.6.1     pkgconfig_2.0.3 
MarkEdmondson1234 commented 3 years ago

Thanks for the feedback! It may be that "byDate" is returning a day with no data and causing a problem? Could you try "byBatch" ? Or change the date ranges to see if you can narrow down when it happens