correct: Correct Character Vector

View source: R/Data_handling.R

correctR Documentation

Correct Character Vector

Description

Substitute given characters or strings by their alternatives.

Usage

correct(x, attr = c("names", "units"), ...)

Arguments

x

A character vector.

attr

A character string identifying an attribute type a character vector x to correct. Can be abbreviated.

...

Further arguments to be passed to the internal make.names function.

Details

The function is intended to simplify the use of variable names and units within the typical processing workflow employing openeddy.

If attr = "names", correction is meant to arrive to syntactically valid names with a higher level of control. This assumes that the original names were preserved during data loading (e.g. by using check.names = FALSE in read_eddy or read.table). Specifically, literal strings are renamed as:

  • "(z-d)/L" by "zeta"

  • "qc_Tau" by "qc_Tau_SSITC"

  • "qc_H" by "qc_H_SSITC"

  • "qc_LE" by "qc_LE_SSITC"

  • "qc_co2_flux" by "qc_NEE_SSITC"

and specified patterns or characters withing strings are substituted using regular expression patterns:

  • "co2_flux" by "NEE"

  • "*" by "star"

  • "%" by "perc"

  • "-" and "/" by "_".

After the substitutions make.names(names = x, ...) is executed.

If attr = "units", round and square brackets are substituted by an empty string.

Value

A corrected character vector.

See Also

make.names.

Examples

correct(c("co2_flux", "qc_co2_flux", "(z-d)/L", "x_70%", "*[-(z-d)/L"))
correct(c("qc_co2_flux", "qc_NEE_SSITC"), unique = TRUE)
correct(c("[m]", "(s)", "kg"), attr = "units")


lsigut/openeddy documentation built on Aug. 5, 2023, 12:25 a.m.