read_data | R Documentation |
Automatic reading in data from a meta-table of external data sets.
read_data(x, ...)
## S3 method for class 'data.frame'
read_data(x, name_variable = "name", file_variable = "file", ...)
## S3 method for class 'character'
read_data(
x,
data_table,
fun = NULL,
frame = parent.frame(),
name_variable = "name",
file_variable = "file",
clean_names_option = FALSE,
remove_blank_rows_cols_option = FALSE,
...
)
x |
character string or data.frame. If it is a character then it is the name of the object to be created, and referenced within the data to find the file path. If it is a dataframe then read_data is repeated across all the rows of the data.frame. |
... |
other arguments to supply to |
name_variable |
character string giving the variable name within
|
file_variable |
character string giving the variable name within
|
data_table |
data frame containing the meta-table of file paths of the external data files, and their desired R object names. |
fun |
the function to be used to read in the data file. If unspecified
it picks up file extensions ".xsl" and ".xslx" to use |
frame |
Environment in which an object with name given by |
clean_names_option |
logical to apply the |
remove_blank_rows_cols_option |
logical to apply the
|
The idea is to improve the tracibility of reading in external data.
This should be used in two steps: create a meta-table in R that has a minimum
of 2 columns, one with the name of the R data.frame to be created, and the
other giving the file path to the external data; use read_data
as a
wrapper to read in the data as specified. This ends up with less code, and
allows an table of extenral data and associated meta-data to
be easily produced using data_table_summary
. If options("verbose") is
TRUE
then read_data
will display messages describing what
objects have been created.
This is a generic method with methods defined for a character string, and a data.frame. The former just reads in one data.frame, the latter reads in all the data.frames specified.
read_data
assigns or returns a data frame reading in data
from an external file
read_data(data.frame)
: data.frame method for read_data generic
read_data(character)
: character method for read_data generic
read.csv
read_excel
data_table_summary
apply_macro_dict
var_lab
extract_form
data_table <- data.frame(
name = c("dirtydata", "meta"),
file = c("dirtydata.csv", "meta_table.xlsx"),
folder = system.file("extdata", package = "cctu"),
stringsAsFactors = FALSE
)
data_table_summary(data_table)
options("verbose" = TRUE)
read_data(data_table)
summary(dirtydata)
summary(meta)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.