Skip to content
Prev 154671 / 398506 Next

Avoiding factors and levels in data frames

Hi Thierry,
On 01-Sep-08 09:45:27, ONKELINX, Thierry wrote:
Yes, that is how I think I see it too. I have now written two
tiny test functions. temp.table() is the same as temp() before [below],
temp.fwf() uses its arguments in the same way as read.fwf().
Also, temp.fwf() calls temp.table() in the same way as read.fwf()
calls read.table() (as far as 'as.is' and 'stringsAsFactors' are
concerned -- I hope!).

  temp.table<-function(as.is = !stringsAsFactors,
          stringsAsFactors = default.stringsAsFactors()){
    print(c(as.is=as.is, sAF=stringsAsFactors))
    }

  temp.fwf<-function(as.is=FALSE,...){ temp.table(as.is=as.is,...) }

and now:

  temp.fwf(as.is=FALSE,stringsAsFactors=FALSE)
# as.is   sAF 
# FALSE FALSE 

  temp.fwf(as.is=FALSE,stringsAsFactors=TRUE)
# as.is   sAF 
# FALSE  TRUE 

  temp.fwf(as.is=TRUE,stringsAsFactors=FALSE)
# as.is   sAF 
#  TRUE FALSE 

  temp.fwf(as.is=TRUE,stringsAsFactors=TRUE)
# as.is   sAF 
#  TRUE  TRUE 

  temp.fwf(stringsAsFactors=TRUE)
# as.is   sAF 
# FALSE  TRUE 

  temp.fwf(stringsAsFactors=FALSE)
# as.is   sAF 
# FALSE FALSE 

showing that the 'as.is' result from temp.fwf() is independent
of any value of 'stringsAsFactors' set in its paramater-list.
I was thinking the same, too.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 01-Sep-08                                       Time: 11:13:12
------------------------------ XFMail ------------------------------