This function saves a data.frame as a .csv
file (using
write.csv
), stores a checksum in '.worcs',
and amends the .gitignore
file to exclude filename
.
open_data(
data,
filename = paste0(deparse(substitute(data)), ".csv"),
codebook = paste0("codebook_", deparse(substitute(data)), ".Rmd"),
value_labels = paste0("value_labels_", deparse(substitute(data)), ".yml"),
worcs_directory = ".",
save_expression = write.csv(x = data, file = filename, row.names = FALSE),
load_expression = read.csv(file = filename, stringsAsFactors = TRUE),
...
)
Returns NULL
invisibly. This
function is called for its side effects.
A data.frame to save.
Character, naming the file data should be written to. By
default, constructs a filename from the name of the object passed to
data
.
Character, naming the file the codebook should be written to.
An 'R Markdown' codebook will be created and rendered to
github_document
('markdown' for 'GitHub').
By default, constructs a filename from the name of the object passed to
data
, adding the word 'codebook'.
Set this argument to NULL
to avoid creating a codebook.
Character, naming the file the value labels of factors
and ordinal variables should be written to.
By default, constructs a filename from the name of the object passed to
data
, adding the word 'value_labels'.
Set this argument to NULL
to avoid creating a file with value labels.
Character, indicating the WORCS project directory to
which to save data. The default value "."
points to the current
directory.
An R-expression used to save the data
.
Defaults to write.csv(x = data, file = filename, row.names = FALSE)
,
which writes a comma-separated, spreadsheet-style file.
The arguments data
and filename
are passed from
open_data()
to the expression defined in save_expression
.
An R-expression used to load the data
from the
file created by save_expression
. Defaults to
read.csv(file = filename, stringsAsFactors = TRUE)
. This expression
is stored in the project's .worcs
file, and invoked by
load_data()
.
Additional arguments passed to and from functions.
open_data closed_data save_data
test_dir <- file.path(tempdir(), "data")
old_wd <- getwd()
dir.create(test_dir)
setwd(test_dir)
worcs:::write_worcsfile(".worcs")
df <- iris[1:5, ]
open_data(df, codebook = NULL)
setwd(old_wd)
unlink(test_dir, recursive = TRUE)
Run the code above in your browser using DataLab