
Use asNumericIfPossible with modified warning.
catch_asNumericIfPossible.RdThis function uses asNumericIfPossible but lets the user change the warning
issued by asNumericIfPossible. Suited for use in other R packages.
Usage
catch_asNumericIfPossible(x, warn, maintain.factor.scores = TRUE,
force.string = TRUE, transform.factors = TRUE)Arguments
- x
A vector or data frame which should be converted.
- warn
A character vector of length 1 with the desired warning.
- maintain.factor.scores
Logical: If
TRUE, conversion of the factor levels is attempted (like inas.numeric(as.character(f))). IfFALSE, the internal codes of the factor are returned (like inas.numeric(f)). See 'Details'. This argument is only evaluated iftransform.factors = TRUE.- force.string
Logical indicating whether columns should be force to numeric, even if NAs are induced. If
FALSE, affected columns are maintained. IfTRUE, conversion is forced.- transform.factors
Logical indicating whether columns of class
factorshould be converted. IfFALSE, columns of classfactorare maintained. IfTRUE, conversion of factors is attempted.
Details
For details see asNumericIfPossible
Examples
char <- c("a", "b", 1)
catch_asNumericIfPossible(x = char, warn = "Vector could not be converted")
#> Warning: Vector could not be converted
#> [1] NA NA 1