read_all_csv {EDCimport} | R Documentation |
Read all .csv
files in a directory
Description
Read all .csv
files in a directory, with labels if specified.
Usage
read_all_csv(
path,
...,
labels_from = NULL,
format_file = NULL,
subdirectories = FALSE,
read_fun = "guess",
datetime_extraction = "guess",
verbose = getOption("edc_read_verbose", 1),
clean_names_fun = NULL
)
Arguments
path |
[ |
... |
unused |
labels_from |
[ |
format_file |
[ |
subdirectories |
[ |
read_fun |
[ |
datetime_extraction |
[ |
verbose |
[ |
clean_names_fun |
|
Value
a list containing one dataframe for each .csv
file in the folder, the extraction date (datetime_extraction
), and a summary of all imported tables (.lookup
).
Labels file
labels_from
should contain the information about column labels. It should be a data file (.csv
) containing 2 columns: one for the column name and the other for its associated label. Use options(edc_col_name="xxx", edc_col_label="xxx")
to specify the names of the columns.
Format file
format_file
should contain the information about SAS formats. It can be either:
a
procformat.sas
file, containing the whole PROC FORMATor a data file (
.csv
or.sas7bdat
) containing 3 columns:-
FMTNAME
the SAS format name (repeated) -
START
the variable level -
LABEL
the label associated to the level
You can get this datafile from SAS using
PROC FORMAT
with optionCNTLOUT
. Otherwise, you can useoptions(edc_var_format_name="xxx", edc_var_level="xxx", edc_var_label="xxx")
to specify different column names.-
See Also
Other EDCimport reading functions:
read_all_sas()
,
read_all_xpt()
,
read_trialmaster()
Examples
# Create a directory with multiple csv files and a label lookup.
path = paste0(tempdir(), "/read_all_csv")
dir.create(paste0(path, "/subdir"), recursive=TRUE)
write.csv(iris, paste0(path, "/iris.csv"))
write.csv(mtcars, paste0(path, "/mtcars.csv"))
write.csv(mtcars, paste0(path, "/subdir/mtcars.csv"))
write.csv(airquality, paste0(path, "/airquality.csv"))
labs = c(iris, mtcars, airquality) %>% names()
write.csv(data.frame(name=labs, label=toupper(labs)), paste0(path, "/labels.csv"))
db = read_all_csv(path, labels_from="labels.csv", subdirectories=TRUE) %>%
set_project_name("My great project")
db
edc_lookup()