new_file_definition_: Helper function for 'new_file_definition()'

Description Usage Arguments

View source: R/file_definition.R

Description

Helper function for new_file_definition()

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
new_file_definition_(
  file_path,
  file_structure,
  to_lower,
  cols_keep,
  extra_col_name = NULL,
  extra_col_val = NULL,
  extra_col_file_path,
  extra_adapters = new_adapters(),
  err_h = composerr("Error while calling 'new_file_definition_()'")
)

Arguments

file_path

A string holding the path to the data file.

file_structure

A file_structure class object. This type of objects can be created by the functions new_file_structure_fwf(), new_file_structure_dsv(), new_file_structure_excel() or new_file_structure_sas() and fully defines the file structure of the data files. The idea is that a single file_structure can be valid for multiple data files and therefore be reused. Whereas a file_definition class object also holds the path to the file and is therefore only valid for a single file.

to_lower

A logical flag, defining if the names of the columns should be transformed to lower case after reading the data set (by calling read_data()). This transformation will be applied before comparing the column names (in the case of SAS-Files or DSV- and EXCE-Files with header = TRUE). In the case of new_file_definition() the to_lower argument overwrites the to_lower argument in the file_structure class object given in file_structure. If to_lower is omitted, then the file_structure class object remains unchanged. In the case of new_file_definition_fwf(), new_file_definition_dsv(), new_file_definition_excel() or new_file_definition_sas() the argument to_lower must either be TRUE or FALSE.

cols_keep

Either TRUE or a character vector. If set to TRUE, then all columns of the data are kept when calling read_data(). If cols_keep character vector, then the values in cols_keep represent the names of the columns, which are kept when calling read_data().

extra_col_name

An optional string, which defines the column, which will be added to the data set (after reading it with function read_data()). Each entry of the column will have the single value given in extra_col_val. For example: This column is useful when reading similar data files for separate years (one could pass the current data set year to extra_col_name and set extra_col_name = "year"). If extra_col_name is omitted, no column will be added to the data set and then extra_col_val must be omitted as well. additional column with the column name, given in extra_col_name. If omitted, then no column will be added to the data set and the argument extra_col_name must be omitted as well.

extra_col_val

An optional value (any atomic type), which will be added (after reading the data set with function read_data()) as an additional column with the column name, given in extra_col_name. For example: This column is useful when reading similar data files for separate years (one could pass the current data set year to extra_col_name and set extra_col_name = "year"). If omitted, then no column will be added to the data set and the argument extra_col_name must be omitted as well.

extra_col_file_path

Either FALSE or a string. If set to FALSE no file-path-column will be added to the data set, when calling read_data(). If the argument extra_col_file_path is a string, then a column holding the file path of the data file will be added to the read data set, when calling read_data(). The string of extra_col_file_path will be used as column name for this additional column.

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 the file_structure class object. For further details on adapter functions see section adapters.

err_h

An error handler


a-maldet/readall documentation built on Dec. 18, 2021, 9:23 p.m.