-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Empty response from Core Reporting API inside a Time Partitioned Query breaks the loop #8
Comments
Any progress on this issue @shahkushan1? Thanks |
@igbuch The workaround I've used is to simply modify GetDataFeed.R locally to: GetDataFeed <- function(query.uri) {
GA.Data <- GET(query.uri)
GA.list <- ParseDataFeedJSON(GA.Data)
if (is.null(GA.list$rows)) {
cat("Your query matched 0 results. Please verify your query using the Query Feed Explorer and re-run it.\n")
# break
return(GA.list)
} else {
return (GA.list)
}
}
The original if (is.null(GA.list$rows)) {
cat("Your query matched 0 results. Please verify your query using the Query Feed Explorer and re-run it.\n")
break
} else {
return (GA.list)
}
} By commenting out the I don't know that this solution is scalable, because there are certainly instances where you wouldn't want to continue hammering the GA API with a daywise query that is fundamentally flawed. In that case, you'd would want the user to verify the query. But for my purposes, I know the query is fine because it's one I regularly use. There just happens to be no matching data on a particular day. This hack lets everything keep moving, but it absolutely does cut out the safety net that keeps you from bombarding the GA API with a query that will never return results and so should be used with some caution. |
Would someone please be kind enough to suggest the equivalent local workaround for GetReportData (instead of GetDataFeed)? I am trying to use GetReportData, and am having exactly the same problem as is described above with null sets, but I don't understand the function above well enough to adapt it to create a version of GetDataFeed that presses on through "Your query matches 0 results..." Thank you very much for your assistance. |
When a query returns a response with zero results, perhaps an empty data.frame (with the appropriate columns (names and data types) but with no rows) could be returned. This way all the responses can be bound together as rows, as they will all have matching data.frame columns. In the In the Hopefully something can be applied here in this package too, probably somewhere in this file I'm guessing: https://github.com/Tatvic/RGoogleAnalytics/blob/master/R/GetDataFeed.R#L16 |
Hi @JIsernhagen @jdeboer, |
Hi Dikesh: are you able to be a little more precise? It would be worth the price of a twelve-pack to me if you implemented the empty set fix this week. |
jdeboer: Can you advise me how to write an outside-the-function error handler which moves on to the next loop element when the "Error in GetDataFeed(query.uri) : no loop for break/next, jumping to top level" message is received? I have read what documentation I can find on try-error and tryCatch and can make no sense of it. All I want is "on-error next"-type functionality in this one, specific case. Thanks for any guidance you can provide. |
I'm not familiar with the error you are describing as I haven't attempted this myself yet. However, if you want to write an exception hander in R, I would certainly recommend the # Try `expr` and catch it if it throws an error, then do something else.
tryCatch(
expr = {
# insert here the code you want to try.
thisFunctionDoesNotExist(1, 2, 3) # An example of something that will throw an error.
},
error = function(e) {
# Leave this empty if you do not want anything to happen when there is an error,
# i.e. the tryCatch will finish and the next command in R will be executed.
# Otherwise, put in the code you want to run if `expr` throws an error.
# You can get information about the error from the object `e`.
message("Ha ha, an error occurred, oh well, who cares?")
message(paste("In case you do care, the error was:", e))
}
# There are other optional arguments too, such as `warning` if you want to handle warnings.
)
# OK, now let's move on to the next thing...
message("Hello world!") I hope the example I have written above is helpful. You can copy and paste it into the R console to see what happens. Good luck! |
I actually got it to work reasonably well using "Try." So thank you for your help. I appreciate your responsiveness. |
@JIsernhagen Would you mind posting your script? I'm having a lot of trouble using TryCatch. Would be very much appreciated! |
The subroutine is legally the property of the company I work for, but here is a relevant subset that should show how "try" can be applied:
|
When extracting unsampled metrics for dimensions like PagePath for a relatively longer date range, the API returns a null response if no data is available for that date. This breaks the loop.
The text was updated successfully, but these errors were encountered: