The documentation of as.data.frame is not explicit about how it generates
column names for the simple vector case, but it seems to use the character
form of the quoted argument, e.g.

names(as.data.frame(1:3))
[1] "1:3"

But there is a strange case:

names(as.data.frame(c("a")))
[1] "if (stringsAsFactors) factor(x) else x"

I feel fairly comfortable calling this a bug, though there is no explicit
specification.

There is another strange case which I don't understand.

The specification of 'optional' is:

   optional: logical. If 'TRUE', setting row names and converting column
          names (to syntactic names: see 'make.names') is optional.

I am not sure what this means and why it is useful.  In practice, it seems
to produce a structure of class data.frame which exhibits some very odd
behavior:

> d <- as.data.frame(c("a"),optional=TRUE)
> class(d)
[1] "data.frame"
> d
  structure("a", class = "AsIs")                   <<< where does this
column name come from?
1                              a
> names(d)
NULL                                            <<< not from names()
> dput(d)
structure(list(structure(1L, .Label = "a", class = "factor")), row.names =
c(NA,
-1L), class = "data.frame")            <<< and it doesn't show up in dput

             -s

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to