Learn R Programming

eatTools (version 0.7.8)

catch_asNumericIfPossible: Use asNumericIfPossible with modified warning.

Description

This 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 in as.numeric(as.character(f))). If FALSE, the internal codes of the factor are returned (like in as.numeric(f)). See 'Details'. This argument is only evaluated if transform.factors = TRUE.

force.string

Logical indicating whether columns should be force to numeric, even if NAs are induced. If FALSE, affected columns are maintained. If TRUE, conversion is forced.

transform.factors

Logical indicating whether columns of class factor should be converted. If FALSE, columns of class factor are maintained. If TRUE, conversion of factors is attempted.

Author

Benjamin Becker

Details

For details see asNumericIfPossible

Examples

Run this code
char <- c("a", "b", 1)
catch_asNumericIfPossible(x = char, warn = "Vector could not be converted")

Run the code above in your browser using DataLab