[R] "methods" package changes class types?
Nunoo, Paa K
Paa.K.Nunoo at FMR.COM
Wed Jan 8 17:57:24 CET 2003
Hi,
Loading the "methods" package into R seems to change the class of a
character vector from NULL to "character":
> class("abcd")
NULL
> library("methods")
> class("abcd")
[1] "character"
This can lead to problems. For example the "as.string" function in the
"xtable" package
assumes that the class of a character vector is NULL. However this changes
when the methods
package is loaded.
Here is a code snippet of the as.string function in the xtable package:
> library(xtable)
> as.string
function (x, file = "", append = FALSE)
{
if (is.null(class(x)))
switch(data.class(x), character = return(string(x, file,
append)), numeric = return(string(as.character(x),
file, append)), stop("Cannot coerse argument to a string"))
if (class(x) == "string")
return(x)
stop("Cannot coerse argument to a string")
}
Why does the methods package change the class of character vectors?
Is there a way around this behavior?
Thanks,
PK
More information about the R-help
mailing list