Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- library("jsonlite")
- library("httr")
- library("lubridate")
- options(stringsAsFactors = FALSE)
- url <- "http://api.kuroganehammer.com"
- ### This gets me a list of 58 observations, I want to use this list to
- ### pull data for each using an API
- raw.characters <- GET(url = url, path = "api/characters")
- ## Convert the results from unicode to a JSON
- text.raw.characters <- rawToChar(raw.characters$content)
- ## Convert the JSON into an R object. Check the class of the object after
- it's retrieved and reformat appropriately
- characters <- fromJSON(text.raw.characters)
- class(characters)
- ## This pulls data for an individual character. I want to get one of
- ## these for all 58 characters by looping this and replacing the 1 in the
- ## URL path for every number through 58.
- raw.bayonetta <- GET(url = url, path = "api/characters/1/detailedmoves")
- text.raw.bayonetta <- rawToChar(raw.bayonetta$content)
- bayonetta <- fromJSON(text.raw.bayonetta)
- ## This is the function I tried to create, but I get a lexical error when
- ## I call it, and I have no idea how to loop it.
- move.pull <- function(x) {
- char.x <- x
- raw.x <- GET(url = url, path = cat("api/characters/",char.x,"/detailedmoves", sep = ""))
- text.raw.x <- rawToChar(raw.x$content)
- char.moves.x <- fromJSON(text.raw.x)
- char.moves.x$id <- x
- return(char.moves.x)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement