This helper function is used by read.table
. When the
data object x
is a data frame or list, the function is called
recursively for each column or list element.
Given a vector, the function attempts to convert it to logical,
integer, numeric or complex, and failing that converts a character
vector to factor unless as.is = TRUE
. The first type that can
accept all the non-missing values is chosen.
Vectors which are entirely missing values are converted to logical,
since NA
is primarily logical.
Vectors containing just F
, T
, FALSE
, TRUE
and values from na.strings
are converted to logical. Vectors
containing optional whitespace followed by decimal constants
representable as R integers or values from na.strings
are
converted to integer. Other vectors containing optional whitespace
followed by other decimal or hexadecimal constants (see
NumericConstants), or NaN
, Inf
or infinity
(ignoring case) or values from na.strings
are converted to
numeric. Where converting inputs to numeric or complex would result
in loss of accuracy they can optionally be returned as strings (for
as.is = TRUE
) or factors.
Since this is a helper function, the caller should always pass an
appropriate value of as.is
.