Learn R Programming

rstan (version 2.15.1)

stan_rdump:

Description

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 (http://mc-stan.org/) or sourced into another R session. The usage of this function is very similar to dump in R.

Usage

stan_rdump(list, file = "", append = FALSE, 
          envir = parent.frame(),
          width = options("width")$width, 
          quiet = FALSE)

Arguments

list
A vector of character string: the names of one or more R objects to be dumped. See the note below.
file
Either a character string naming a file or a connection. "" indicates output to the console.
append
Logical: if TRUE and file is a character string, output will be appended to file; otherwise, it will overwrite the contents of file.
envir
The environment to search for objects.
width
The width for maximum characters on a line. The output is broken into lines with width.
quiet
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.

Value

An invisible character vector containing the names of the objects that were dumped.

References

The Stan Development Team Stan Modeling Language User's Guide and Reference Manual. http://mc-stan.org.

See Also

dump

Examples

Run this code
# set variables in global environment
a <- 17.5
b <- c(1,2,3)
# write variables a and b to file ab.data.R in working directory
stan_rdump(c('a','b'), "ab.data.R")

x <- 1; y <- 1:10; z <- array(1:10, dim = c(2,5)) 
stan_rdump(ls(pattern = '^[xyz]'), "xyz.Rdump")
cat(paste(readLines("xyz.Rdump"), collapse = '\n'), '\n')
unlink("xyz.Rdump")

Run the code above in your browser using DataLab