make_loq: Extract numeric, below/above the lower/upper limits of...

View source: R/data_cleaners.R

make_loqR Documentation

Extract numeric, below/above the lower/upper limits of quantification (LLQ and ULQ), and text data from a vector.

Description

Extract numeric, below/above the lower/upper limits of quantification (LLQ and ULQ), and text data from a vector.

Usage

make_loq(
  x,
  llq_pattern = "^< *\\(? *([0-9]*\\.?[0-9]+) *\\)?$",
  ulq_pattern = "^> *\\(? *([0-9]*\\.?[0-9]+) *\\)?$",
  number_pattern = "^(+-)?[0-9]+(\\.[0-9]*)?([eE][+-]?[0-9]+)?$",
  replace_llq = 0,
  replace_ulq = Inf,
  ...
)

Arguments

x

The character vector to extract data from.

llq_pattern, ulq_pattern

A regex or vector of regex values for extracting llq and ULQ. If a vector, all regexes will be tested.

number_pattern

A regex or vector of regex values for finding numbers.

replace_llq, replace_ulq

The value to place in the "number" column when a llq/ulq is matched (typically 0 and Inf, respecitvely or NA_real_ for both).

...

Parameters passed to grep and grepl for llq_pattern searching.

Details

If llq_pattern or ulq_pattern are regular expressions that extract a value, then the extracted value will be used in the "llq"/"ulq" column. If not, then the value -1 will be inserted. If all "llq"/"ulq" values match the number_pattern, then the "llq"/"ulq" columns will be converted to numeric (if not, a warning will be given).

Value

a data.frame with columns named "text", "number", "llq", and "ulq".

Examples

make_loq(c("1", "A", "<1", ">60"))
make_loq(c("1", "A", "<1", ">60"), replace_llq=NA_real_)
make_loq(c("1", "A", "<1", ">60"), replace_llq=NA_real_, replace_ulq=NA_real_)
make_loq(c("1", "A", "<1", ">ULQ"), replace_llq=NA_real_, replace_ulq=NA_real_)
make_loq(c("1", "A", "<1", ">ULQ"), replace_llq=NA_real_, replace_ulq=NA_real_, ulq_pattern=">ULQ")

billdenney/bsd.report documentation built on Jan. 16, 2024, 12:54 a.m.