as_num {teal.modules.clinical} | R Documentation |
Parse text input to numeric vector
Description
Generic to parse text into numeric vectors. This was initially designed for a robust interpretation of text input in teal modules.
Usage
as_num(str)
## Default S3 method:
as_num(str)
## S3 method for class 'character'
as_num(str)
## S3 method for class 'numeric'
as_num(str)
## S3 method for class 'factor'
as_num(str)
## S3 method for class 'logical'
as_num(str)
Arguments
str |
( |
Details
The function is intended to extract any numeric from a character string, factor levels, boolean and return a vector of numeric.
Value
As vector of numeric if directly parsed from numeric
or boolean.
A list of numeric if parsed from a character string, each character string
associated with an list item.
Examples
dta <- list(
character = c("text10,20.5letter30.!", "!-.40$$-50e5[", NA),
factor = factor(c("]+60e-6, 7.7%%8L", "%90sep.100\"1L", NA_character_)),
numeric = c(1, -5e+2, NA),
logical = c(TRUE, FALSE, NA)
)
lapply(dta, as_num)
[Package teal.modules.clinical version 0.9.1 Index]