warning message for setAs when using class AsIs

John Chambers jmc@research.bell-labs.com
Wed, 29 May 2002 11:45:49 -0400


"David Kane
> 
> This seemed too advanced for r-help and is related to the recent discussion of
> character vectors in dataframes.
> 
> Following Brian Ripley's most excellent advice, we are moving to a world in
> which character vectors in dataframes are always of class AsIs. The cool way of
> doing this seemed to be the following:
> 
> > cat(c("x", "y", "z"), file = "test.txt", sep = "\n")
> > x <- read.table("test.txt")
> > class(x$V1)
> [1] "factor"
> 
> This is what we expect.
> 
> > library(methods)
> > setAs('character', "AsIs", function(from) I(from))
> Warning message:
> Class "AsIs"not defined in: matchSignature(fnames, signature, fdef)
> >
> 
> This warning seems wrong to me, although I am not smart enough to follow the
> logic through the underlying code. It *seems* as if setAs does not consider
> `AsIs' to be an allowed class. However, the desired effect is achieved.

In the sense of the methods package (i.e., of "S4" classes) the class
"AsIs" and all S3-style classes are undefined.  Literally, in that there
is no object containing their definition.

In general, mixing old and new classes can cause confusion.  In this
case, you will be OK if the as() function finds a specific method to
coerce character to "AsIs".  The warning is saying that there won't be
any way to infer inheritance for the class "AsIs", but inheritance for
the target class is not important for the call to as().

John

PS: the current version of read.table implicitly requires the methods
package if the argument colClasses is supplied.  Should that be made
explicit?

Otherwise, users get errors if they forget library(methods):

R> x <- read.table("testR/test.txt", colClasses=c("AsIs"))
Error: couldn't find function "as"




> 
> > x <- read.table("test.txt", colClasses=c("AsIs"))
> > x
>   V1
> 1  x
> 2  y
> 3  z
> > class(x$V1)
> [1] "AsIs"      "character"
> > unlink("test.txt")
> > R.version
>          _
> platform sparc-sun-solaris2.6
> arch     sparc
> os       solaris2.6
> system   sparc, solaris2.6
> status
> major    1
> minor    5.0
> year     2002
> month    04
> day      29
> language R
> >
> 
> Any comments/suggestions would be much appreciated.
> 
> Thanks,
> 
> Dave Kane
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
> r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
> _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

-- 
John M. Chambers                  jmc@bell-labs.com
Bell Labs, Lucent Technologies    office: (908)582-2681
700 Mountain Avenue, Room 2C-282  fax:    (908)582-3340
Murray Hill, NJ  07974            web: http://www.cs.bell-labs.com/~jmc
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._