write_obj | R Documentation |
This function is a wrapper around dput
that allows you
to write an R object as part of a knitr document as an output for
later use. It is designed to be used in a code block. The file name, if
not specified, will be the label of the code block. Use the standard
dget
function to read the file back into an R session.
write_obj(obj, file = NULL, target_dir = NULL, ...)
obj |
The R object to be written. |
file |
The name of the file to be written. If not specified, the label of the code block will be used. |
target_dir |
The directory where the file will be written. If not specified, the current working directory will be used. |
... |
Additional arguments to be passed to |
The path of the written file.
## Not run:
obj_dir <- file.path(tempdir(), "obj")
# Write a data frame as a file
write_obj(
obj = mtcars,
file = "mtcars_data",
target_dir = obj_dir)
# Read the file back into an R session
my_mtcars <- dget(file.path(obj_dir, "mtcars_data"))
unlink(obj_dir)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.