I'm trying to convert three lines of R code into an elegant one liner using %>% for a bit of fairly simple code that gets data from an API, transforms the Unicode into JSON and then into a char type that I can use as data.
Libraries: httr, jsonlite, tidyverse
</> res = GET("http://api.open-notify.org/astros.json")
</>data = fromJSON(rawToChar(res$content))
Because I like slick, I wanted to make those three lines into one command using %>%, like so:
</>data <- fromJSON(rawToChar(res$content)) %>% GET("http://api.open-notify.org/astros.json")
But that fails with this error code:
Error in parse_url(url) : length(url) == 1 is not TRUE
Any idea why?
Many thanks in advance!