dfToJSON: Converts data to json form

Description Usage Arguments Author(s) References Examples

View source: R/json.R

Description

Creates a json file from an input

Usage

1
dfToJSON(df, mode = "vector")

Arguments

df

a data.frame to be converted

mode

there are four modes "vector", "coords" , "rowToObject", "hierarchy"

Author(s)

Simon Raper

References

I got the code for the recursive function that makes the json hierarchy from someone on stack overflow. I'm sorry I was going to credit them but can no loner find the post. Let me know if it's you!

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
data(iris)
jsonOut<-dfToJSON(iris)
fileConn<-file("iris.json")
writeLines(jsonOut, fileConn)
close(fileConn)

jsonOut<-dfToJSON(iris, mode="rowToObject")
fileConn<-file("irisRows.json")
writeLines(jsonOut, fileConn)
close(fileConn)

jsonOut<-dfToJSON(iris, mode="coords")
fileConn<-file("irisCoords.json")
writeLines(jsonOut, fileConn)
close(fileConn)

tree<-dcast(data=iris, Species+Petal.Width ~ .)
jsonOut<-dfToJSON(iris, mode="hierarchy")
fileConn<-file("irisTree.json")
writeLines(jsonOut, fileConn)
close(fileConn)

jamesthomson/R2D3 documentation built on May 18, 2019, 11:21 a.m.