我正在使用googleanalyticsR從Google Analytics下載所有數據我的目標是構建一個小數據框來分析。Loop googleanalyticsR - 錯誤if(nrow(out)<all_rows {:參數長度爲零
要下載的所有數據我創建了一個循環:
for (i in 1:length(metricsarray)) {
print(paste(i))
tryCatch( google_analytics_4(my_id,
date_range = c(start_date, end_date),
metrics = metricsarray[i],
dimensions = c('transactionId'),
max = -1)) %>%
assign(gsub(" ", "", paste("metricsarray",i, sep="")), ., inherits = TRUE)
}
循環從1到11,沒有任何問題,即打印我的號碼,給我的留言:
Downloaded [3537] rows from a total of [3537]
但是,當它達到I =在metricsarray 12 I得到這個錯誤[I]:
2017-10-04 10:37:56> Downloaded [0] rows from a total of []. Error in if (nrow(out) < all_rows) { : argument is of length zero
我用tryCatch,但沒有效果,它繼續。我的目標是它會繼續測試每個指標,直到最後。 此外,還繼續當它發現錯誤:
JSON fetch error: Selected dimensions and metrics cannot be queried together.
我是新來的R中使用Google分析API,隨時提出解決方案,文章或任何東西,我們可能會認爲它會幫助我獲得更多這方面的知識。 謝謝
tryCatch應該爲你的用例工作,反而會發生什麼?我做類似的,它的工作正常。如果更容易,請隨時在GitHub上提出問題。 – MarkeD