replaceVals: User-intended wrapper for single-file replacements

View source: R/valReplacement.R

replaceValsR Documentation

User-intended wrapper for single-file replacements

Description

The function sends the prepared data.tables to sReplace, receives updated data, displays a list of updated data and of counts of multiple replacements and saves updated data to disk (see Details).

Usage

replaceVals(dir, ..., save = TRUE)

Arguments

dir

Quoted character of length = 1 describing the path to the directory containing the data and associated lookup files, with either forward or double backward slash and no end slash (e.g. "C:/path/to/directory").

...

Not used when file names are "data.csv", "lookup.csv". Otherwise, custom names including file extension, within quotation marks, such as "<data_name>.csv", "<lookup_name>.csv", entered in this order!.

save

Logical, default TRUE: save results to dir. FALSE: display only. See Note below.

Details

The workflow:

Tasks

The function reads the data/lookup pair converting each file to "data.table" class, performs conformance checks on associated lookup, removes uninvolved data columns and non-standard lookup columns. Upon return from sReplace, re-structures updated result in the original format, saves the updated data to dir and displays a one-run named list containing updated data along with counts of duplicated and/or missing values replacements requests.

Messages

The function displays messages and comments regarding the internal workflow. It is recommended reading these messages/comments as first troubleshooting step since they are specific to each file pair and request type. To suppress messages, wrap the function with suppressMessages. The vignette contains definitions of terms.

Value

A named list containing updated data and multiple replacement counts. Also, a csv file saved in the same directory, under the name updated_<data_name>using<lookup_name>.csv.

Note

In examples, please leave argument save to FALSE. Otherwise, copy all content of folder "extdata" found in the installed package root into a directory on your machine. Use the absolute path to this directory as dir argument.

See Also

bReplace, sReplace

Examples


## Not run: datasets with default names "data.csv", "lookup.csv" located in *dir*

if (interactive()) {
 dir = system.file("extdata", package = "replacer")
 replaceVals(dir, save = FALSE)

  ## no messages (not recommended!)
 suppressMessages(replaceVals(dir, save = FALSE))
 }


replacer documentation built on Aug. 20, 2022, 1:06 a.m.