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": [ #> [1.58069945043383, -2.37080962953567], #> [0.940040246321862, -1.25325860935484], #> [1.13143023201082, -0.174847951632965], #> [-0.213695900693846, 0.108511592901088], #> [0.95783890475, 0.516920454312649] #> ], #> "y": [12, 8, 8, 8, 8], #> "z": [1, 0] #> }