Prof. Walmes Marques Zeviani
30 Mar 2017
jsonlite::fromJSON()
library(jsonlite)
url <- "http://samples.openweathermap.org/data/2.5/weather?lat=35&lon=139&appid=b1b15e88fa797225412429c1c50c122a1"
clima <- fromJSON(url)
str(clima)
url <- "http://samples.openweathermap.org/data/2.5/weather?q=London,uk&appid=b1b15e88fa797225412429c1c50c122a1"
clima <- fromJSON(url)
str(clima)
args(fromJSON)
## function (txt, simplifyVector = TRUE, simplifyDataFrame = simplifyVector,
## simplifyMatrix = simplifyVector, flatten = FALSE, ...)
## NULL
a <- "[10, 20, 30]"
a <- matrix(1:9, 3, 3)
toJSON(a)
## [[1,4,7],[2,5,8],[3,6,9]]
p <- head(precip)
p
## Mobile Juneau Phoenix Little Rock Los Angeles
## 67.0 54.7 7.0 48.5 14.0
## Sacramento
## 17.2
toJSON(p)
## [67,54.7,7,48.5,14,17.2]
toJSON(as.list(p))
## {"Mobile":[67],"Juneau":[54.7],"Phoenix":[7],"Little Rock":[48.5],"Los Angeles":[14],"Sacramento":[17.2]}
args(toJSON)
## function (x, dataframe = c("rows", "columns", "values"), matrix = c("rowmajor",
## "columnmajor"), Date = c("ISO8601", "epoch"), POSIXt = c("string",
## "ISO8601", "epoch", "mongo"), factor = c("string", "integer"),
## complex = c("string", "list"), raw = c("base64", "hex", "mongo"),
## null = c("list", "null"), na = c("null", "string"), auto_unbox = FALSE,
## digits = 4, pretty = FALSE, force = FALSE, ...)
## NULL
toJSON(mtcars)