This function takes a vector of names of R objects and outputs
text representations of the objects to a file or connection.
The file created by
stan_rdump is typically used as data
input of the Stan package (https://mc-stan.org/) or
sourced into another R session. The usage of
this function is very similar to
dump in R.
stan_rdump(list, file = "", append = FALSE, envir = parent.frame(), width = options("width")$width, quiet = FALSE)
A vector of character string: the names of one or more R objects to be dumped. See the note below.
Either a character string naming a file or a
The environment to search for objects.
The width for maximum characters on a line.
The output is broken into lines with
Whether to suppress warning messages that would appear when a variable is not found or not supported for dumping (not being numeric or it would not be converted to numeric) or a variable name is not allowed in Stan.
An invisible character vector containing the names of the objects that were dumped.
stan_rdump only dumps numeric data, which first can be
a scalar, vector, matrix, or (multidimensional) array. Additional types
data.frame and a specially structured
The conversion for logical variables is to map
TRUE to 1
FALSE to 0. For
factor variable, function
as.integer is used to do the conversion (If we want to transform a
f to approximately its original numeric values, see the help of
factor and do the transformation before calling
In the case of
data.matrix is applied to the data frame before
dumping. See the notes in stan for the specially
list, which will be converted to
array before dumping.
stan_rdump will check whether the names of objects
are legal variable names in Stan. If an illegal name is
found, data will be dumped with a warning. However, passing the
name checking does not necessarily mean that the name is
legal. More details regarding rules of variable names in Stan can
be found in Stan's manual.
If objects with specified names are not found, a warning will be issued.
The Stan Development Team Stan Modeling Language User's Guide and Reference Manual. https://mc-stan.org.
# set variables in global environment a <- 17.5 b <- c(1,2,3) # write variables a and b to file ab.data.R in temporary directory stan_rdump(c('a','b'), file.path(tempdir(), "ab.data.R")) unlink(file.path(tempdir(), "ab.data.R")) x <- 1; y <- 1:10; z <- array(1:10, dim = c(2,5)) stan_rdump(ls(pattern = '^[xyz]'), file.path(tempdir(), "xyz.Rdump")) cat(paste(readLines(file.path(tempdir(), "xyz.Rdump")), collapse = '\n'), '\n') unlink(file.path(tempdir(), "xyz.Rdump"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.