checkUnitPrefix {wrMisc}R Documentation

Check For Common Unit-Name in Text

Description

This function aims to find a unit abbreviation or name occurring in all elements of a character-vector x. The unit name may be preceeded by different decimal prefixes (eg 'k','M'), as defined by argument pref and separators (sep). The unit name will be returned (or first of multiple).

Usage

checkUnitPrefix(
  x,
  pref = c("a", "f", "p", "n", "u", "m", "", "k", "M", "G", "T", "P"),
  unit = c("m", "s", "sec", "Mol", "mol", "g", "K", "cd", "A", "W", "Watt", "V", "Volt"),
  sep = c("", " ", ";", ",", "_", "."),
  sep2 = "",
  stringentSearch = FALSE,
  na.rm = FALSE,
  protSpecChar = TRUE,
  inclPat = FALSE,
  callFrom = NULL,
  silent = FALSE,
  debug = FALSE
)

Arguments

x

(character) vector containing digit uunit-prefix and unit terms

pref

(character) multiplicative unit-prefixes, assumes as increasing factors of 1000

unit

(character) unit name, the numeric part may be sepatated by one space-character

sep

(character) separator character(s) that may appear between integer numeric value and unit-prefix

sep2

(character) separator character(s) after unit, set to sep2="" for ignoring characters following unit

stringentSearch

(logical) if TRUE only matches with same separators (sep, sep2) pass, otherwise different elements may contain different separators

na.rm

(logical) remove NA from input

protSpecChar

(logical) protect special characters and use as they are instead of regex-meaning

inclPat

(logical) return list including pattern of successful search

callFrom

(character) allow easier tracking of messages produced

silent

(logical) suppress messages

debug

(logical) additional messages for debugging

Details

Basically this function searches the pattern : digit + separator(sep) + prefix(pref) + unit + optional separator2(sep2) and returns the first unit-name/abbreviation found in all elements of x.

If if() In case of invalid entries or no common unit-names NULL will be returned.

Please note the 'u' is used for 'micro' since handeling of special characters may not be portal between different operating systems.

Value

This function returns a charcter vector (length=1) with the common unit name, if inclPat=TRUE it returns a list with $unit and $pattern

See Also

convToNum; adjustUnitPrefix

Examples

x1 <- c("10fg WW","xx 10fg 3pW"," 1pg 2.0W")
checkUnitPrefix(x1)
## different separators between digit and prefix:
x2 <- c("10fg WW","xx 8_fg 3pW"," 1 pg-2.0W")
checkUnitPrefix(x2, stringentSearch=TRUE)
checkUnitPrefix(x2, stringentSearch=FALSE)

x4 <- c("CT_mixture_QY_50_amol_CN_UPS1_CV_Standards_Research_Group",
  "CT_mixture_QY_5_fmol_CN_UPS1_CV_Standards_Research_Group")


[Package wrMisc version 1.15.1 Index]