Description Usage Arguments Value File types difference file_structure/file_definition/file_collection adapters
View source: R/file_collection.R
With the function read_data()
you can read FWF-, DSV-, EXCEL- or SAS data files
and store the data in a data.frame.
But with read_data()
you can also read multiple data files
at once and automatically concatenate
the resulting data.frames into a single data.frame. In order to do so,
you need to create a
list of [file_definition class][new_file_definition()]
objects.
This file_definitionuration list
is a file_collection
class object and each
list entry a file_definition class class object holding all
information needed for reading a specific data file.
Each file_definitionuration list entry can be created by using one of the following
functions:
new_file_definition()
for FWF, DSV or EXCEL data files
new_file_definition_fwf()
for FWF data files
new_file_definition_dsv()
for DSV data files
new_file_definition_excel()
for EXCEL data files
new_file_definition_sas()
for SAS data files
1 2 3 4 5 6 7 | new_file_collection(
...,
to_lower = NULL,
cols_keep = NULL,
extra_col_file_path = NULL,
extra_adapters = new_adapters()
)
|
... |
Multiple file file_definitionurations. This file file_definitionurations can be
created with the functions |
to_lower |
An optional logical argument.
If omitted, then the |
cols_keep |
An optional argument, which can either be |
extra_col_file_path |
An optional argument, which can either be
|
extra_adapters |
An optional adapters class object,
which holds a list of adapter functions. These adapter functions will
be added to the adapter functions already stored in each file
file_definitionuration passed in via |
A list, where each list entry is file file_definitionuration,
which holds all information needed to read a specific data file with the
function read_data()
.
The function read_data()
can read read four different types of data
FWF
: Fixed width files. This files are text files, where the data is
stored in columns, that have a fixed character width.
DSV
: Delimiter-separated value file. This files are text files, where
the data is stored in columns that are separated by a delimiter character.
EXCEL
: An excel file holding the data.
SAS
: A SAS file holding the data.
In order to read a data file with the function read_data()
,
it is useful to create a file_definitionuration or
file_structure class object,
holding all needed data file file_structures:
new_file_definition_fwf()
or new_file_structure_fwf()
for FWF
files
new_file_definition_dsv()
or new_file_structure_dsv()
for DSV
files
new_file_definition_excel()
or new_file_structure_excel()
for Excel
files
new_file_definition_sas()
or new_file_structure_sas()
for SAS
files
The goal of the package readall
is it to read data files. For this
purpose the package offers three different class objects in order to
store meta data about the data files:
file_structure class objects: Objects of this
class can be used in order to define
all file type specific information (e.g. column positions,
column names, column types, deliminator symbols, rows to skip etc.).
The idea is, that one file_structure
object may valid for several files
and therefore be used to read multiple data files.
file_definition class objects: Objects of this class type contain all informations in order to read a single specific data file (path to the data file, file file_structure etc.). A file_definition class object contains a file_structure, which holds all file type specific information, but also other informations that are only valid for this specific file.
file_collection class objects: A file_collection class object is simply a list holding multiple file_definition class objects. A file_collection class object can be used in order to read several data files at once and concatenate the data into a single data.frame.
An adapter function is a function that takes a data.frame as input argument
and returns a modified version of this data.frame.
The adapter functions are stored in an adapters
class object, which is a special list that contains all adapter functions
and a description text of each function. This class objects can be
created by using the function new_adapters()
.
The adapters class objects can be added to a
file_structure or a
file_definition or a file_collection class object.
After reading a data file (by calling read_data(file_definition))
all adapter functions listed in the adapters
argument of the
file_definition]new_file_definition()
class object
will be applied consecutively to the loaded data set.
Adapter functions can be added to an existing
file_structure or a file_definition or
a file_collection class
object by using the function add_adapters()
.
Adapter functions can be used for several tasks:
adapt the data sets in such a way that they can be concatenated for mutliple years
compute new variables from existing variables
fix errors in variables
transform the values of a variable of an older data set, such that it complies with a newer variable definition
An adapter function is a function that takes a data.frame as input argument
and returns a modified version of this data.frame.
The adapter functions are stored in an adapters
class object, which is a special list that contains all adapter functions
and a description text of each function. This class objects can be
created by using the function new_adapters()
.
The adapters class objects can be added to a
file_structure or a
file_definition or a file_collection class object.
After reading a data file (by calling read_data(file_definition))
all adapter functions listed in the adapters
argument of the
file_definition]new_file_definition()
class object
will be applied consecutively to the loaded data set.
Adapter functions can be added to an existing
file_structure or a file_definition or
a file_collection class
object by using the function add_adapters()
.
Adapter functions can be used for several tasks:
adapt the data sets in such a way that they can be concatenated for mutliple years
compute new variables from existing variables
fix errors in variables
transform the values of a variable of an older data set, such that it complies with a newer variable definition
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.