[R] example methods for "whatis"

White.Denis@epamail.epa.gov White.Denis at epamail.epa.gov
Fri Feb 14 00:16:03 CET 2003


Having difficulty following the examples in John Chambers paper "Classes
and Methods in the S Language", dated 9 August 2001.  See error below in
whatis (matrix (0,2,3)).  Thanks for help.

> library (methods)
> whatis <- function (object) paste ("an object of class",
+     data.class (object))
> setMethod ("whatis", "vector", function (object)
+     paste (data.class (object), "vector of length",
+       length (object)))
Creating a new generic function for "whatis" in package
.GlobalEnv
[1] "whatis"
> whatIsMatrix <- function (object)
+     paste (data.class (as (object, "vector")), "matrix with",
+         nrow (object), "rows and", ncol (object), "columns")
> setMethod ("whatis", "matrix", whatIsMatrix)
[1] "whatis"
> whatis (matrix (0,2,3))
Error in paste(".", prefix, name, sep = "__") :
        evaluation is nested too deeply: infinite recursion?
> R.version
         _
platform i386-pc-mingw32
arch     i386
os       mingw32
system   i386, mingw32
status
major    1
minor    6.2
year     2003
month    01
day      10
language R




More information about the R-help mailing list