Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
added handler for weird single left bracket return fix #51
Browse files Browse the repository at this point in the history
  • Loading branch information
sckott committed May 13, 2015
1 parent ffba200 commit 0c540f3
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@ sc <- function(x){
}

return_obj <- function(x, y){
y <- err_hand(y)
x <- match.arg(x, c('response', 'list', 'table', 'data.frame'))
if (x == 'response') {
y
} else {
out <- content(y, as = "text")
if (x == 'list') {
fromJSON(out, simplifyVector = FALSE, flatten = TRUE)
fromJSON(y, simplifyVector = FALSE, flatten = TRUE)
} else {
fromJSON(out, flatten = TRUE)
fromJSON(y, flatten = TRUE)
}
}
}

# check if stupid single left bracket returned
err_hand <- function(z) {
tmp <- content(z, "text")
if (identical(tmp, "[")) {
q <- parse_url(z$request$opts$url)$query
q <- paste0("\n - ", paste(names(q), q, sep = "="), collapse = "")
stop("The following query had no results:\n", q, call. = FALSE)
} else {
tmp
}
}

give_noiter <- function(as, url, endpt, args, ...) {
tmp <- return_obj(as, query(paste0(url, endpt), args, ...))
switch(as,
Expand Down

0 comments on commit 0c540f3

Please sign in to comment.