Skip to content
Prev 20786 / 63421 Next

Changing the generic of as.data.frame

On Mon, 22 May 2006, Prof Brian Ripley wrote:

            
I just noticed that data.frame accepts a vector of logicals for
stringsAsFactors: one element per ... argument.  This is not in
the help file.

   Splus> data.frame
   function(..., row.names = NULL, check.rows = F, check.names = T, na.strings =
           "NA", dup.row.names = F, stringsAsFactors = default.stringsAsFactors(
           ))
   {
           dots <- match.call(expand.dots = F)$...
           n <- length(dots) - 1
           ...
           stringsAsFactors <- rep(stringsAsFactors, len = n)
           for(i in seq(length = n)) {
                   xi <- data.frameAux(eval(as.name(paste("..", i, sep = ""))),
                           na.strings = na.strings, stringsAsFactors =
                           stringsAsFactors[i])


Splus's importData(), which outputs a data.frame from a various other
file formats or database connections, also uses stringsAsFactors.

It also affects as.data.frame() and the character method for data.frameAux()
(which is not expected to be called directly -- it is a support function for
data.frame() and as.data.frame()).

In the bigdata library bdFrame() uses it in the same way that data.frame()
does.

There may be a few stray functions that pass their ... arguments
to data.frame, but I cannot think of any now.

Its default value should always be default.stringsAsFactors(),
but I see the bdFrame() uses just FALSE.  default.stringsAsFactors()
looks at options("stringsAsFactor") and maps NULL and TRUE to TRUE.
    Splus> default.stringsAsFactors
    function()
    {
            val <- .Options$stringsAsFactors
            if(is.null(val))
                    val <- T
            if(!is.logical(val) || is.na(val) || length(val) != 1)
                    stop("options('stringsAsFactors') not set to T or F")
            val
    }

I believe that Terry Therneau has been using Splus with
options(stringsAsFactors=FALSE) for quite a while and hasn't reported
any problems.
----------------------------------------------------------------------------
Bill Dunlap
Insightful Corporation
bill at insightful dot com
360-428-8146

 "All statements in this message represent the opinions of the author and do
 not necessarily reflect Insightful Corporation policy or position."