creating a function that converts GET() results to a data frame

Hey there,

trying to write a function that invokes other functions from the httr and jsonlite packages

What I want the function to do is take the result of a GET() call and then go through the steps of converting to text then to json then to a data frame, and the output would be a data frame

Here is what I have so far

crime_test < GET("https://api.usa.gov/crime/fbi/sapi/api/summarized/state/AL/homicide/2000/2010?API_KEY={ }")

convert_df <- function(obj){
  content(obj, "text") -> x
  fromJSON(x, flatten=TRUE) -> y
  as.data.frame(y)
}

convert_df(obj=crime_test)

#  Error in content(obj, "text") : is.response(x) is not TRUE 
#4. stop(simpleError(msg, call = if (p <- sys.parent(1L)) sys.call(p))) 
#3.stopifnot(is.response(x)) 
#2.content(obj, "text") 
#1.convert_df(obj = "crime_test")

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.