Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. library("jsonlite")
  2. library("httr")
  3. library("lubridate")
  4. options(stringsAsFactors = FALSE)
  5. url <- "http://api.kuroganehammer.com"
  6.  
  7. ### This gets me a list of 58 observations, I want to use this list to
  8. ### pull data for each using an API
  9.  
  10. raw.characters <- GET(url = url, path = "api/characters")
  11. ## Convert the results from unicode to a JSON
  12. text.raw.characters <- rawToChar(raw.characters$content)
  13. ## Convert the JSON into an R object. Check the class of the object after
  14. it's retrieved and reformat appropriately
  15. characters <- fromJSON(text.raw.characters)
  16. class(characters)
  17.  
  18. ## This pulls data for an individual character. I want to get one of
  19. ## these for all 58 characters by looping this and replacing the 1 in the
  20. ## URL path for every number through 58.
  21. raw.bayonetta <- GET(url = url, path = "api/characters/1/detailedmoves")
  22. text.raw.bayonetta <- rawToChar(raw.bayonetta$content)
  23. bayonetta <- fromJSON(text.raw.bayonetta)
  24.  
  25. ## This is the function I tried to create, but I get a lexical error when
  26. ## I call it, and I have no idea how to loop it.
  27. move.pull <- function(x) {
  28. char.x <- x
  29. raw.x <- GET(url = url, path = cat("api/characters/",char.x,"/detailedmoves", sep = ""))
  30. text.raw.x <- rawToChar(raw.x$content)
  31. char.moves.x <- fromJSON(text.raw.x)
  32. char.moves.x$id <- x
  33. return(char.moves.x)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement