Write data to a JSON file readable by CmdStan

write_stan_json(data, file)

Arguments

data

A named list of R objects.

file

A string specifying the path to where the data file should be written.

Examples

x <- matrix(rnorm(10), 5, 2) y <- rpois(nrow(x), lambda = 10) z <- c(TRUE, FALSE) data <- list(N = nrow(x), K = ncol(x), x = x, y = y, z = z) # write data to json file file <- tempfile(fileext = ".json") write_stan_json(data, file) # check the contents of the file cat(readLines(file), sep = "\n")
#> { #> "N": 5, #> "K": 2, #> "x": [ #> [-0.46463062606926, 0.906218004651404], #> [1.21428942140779, 0.781674865660302], #> [0.661948915176096, -0.257065264504065], #> [-0.925800297746062, -1.19855619881824], #> [-0.778266018414021, -1.03512066022385] #> ], #> "y": [8, 13, 9, 10, 14], #> "z": [1, 0] #> }