[Rd] warning creating an as.array method in a package
Michael Friendly
friendly at yorku.ca
Fri Dec 10 16:18:49 CET 2010
I found a solution to this problem, but don't understand why it was
necessary. In a clean workspace, I get:
> methods(as.array)
[1] as.array.default
> showMethods("as.array")
Function "as.array":
<not a generic function>
So, I just added the generic definition to my package, making with
warnings go away.
as.array <- function(x, ...)
UseMethod("as.array")
as.array.loddsratio <- function (x, log=x$log, ...)
drop(array(coef(x, log = log), dim = dim(x), dimnames=dimnames(x)))
Yet, help(as.array) says:
as.array is a generic function for coercing to arrays. The default
method does so by attaching a dim attribute to it. It also attaches
dimnames if x has names. Is this a documentation error?
> sessionInfo()
R version 2.11.1 (2010-05-31)
i386-pc-mingw32
locale:
[1] LC_COLLATE=English_United States.1252
[2] LC_CTYPE=English_United States.1252
[3] LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United States.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
loaded via a namespace (and not attached):
[1] tools_2.11.1
>
On 12/9/2010 10:05 AM, Michael Friendly wrote:
> I posted on this topic to r-help, but never got a sufficient answer, so
> I'm reposting here.
>
> [Env: R 2.11.1, Win Xp, using Eclipse/StatET]
>
> In a package I'm working on, I want to create as.matrix() and as.array()
> methods for a particular kind of
> object (log odds ratios). These are returned in a loddsratio object as
> the $coefficients component,
> a vector, but really reflect an underlying (R-1)x(C-1)xstrata array,
> whose attributes are contained in other components.
>
> These are all properly declared in the NAMESPACE as S3 methods,
>
> ...
> S3method(dim, loddsratio)
> S3method(dimnames, loddsratio)
> S3method(print, loddsratio)
> S3method(vcov, loddsratio)
> S3method(as.matrix, loddsratio)
> S3method(as.array, loddsratio)
>
> Yet, when I run R CMD check, R CMD build, etc. or even load the package,
> I get the warning,
>
> > library(vcdExtra)
> Loading required package: vcd
> Loading required package: MASS
> Loading required package: grid
> Loading required package: colorspace
> Loading required package: gnm
> Warning message:
> found an S4 version of ‘as.array’ so it has not been imported correctly
>
> > showMethods("as.array")
> Function: as.array (package base)
> x="ANY"
> x="Matrix"
>
> But as.array does show up as a method for my class:
>
> > methods(class="loddsratio")
> [1] as.array.loddsratio* as.data.frame.loddsratio*
> [3] as.matrix.loddsratio* coef.loddsratio*
> [5] confint.loddsratio* dim.loddsratio*
> [7] dimnames.loddsratio* print.loddsratio*
> [9] vcov.loddsratio*
>
> Non-visible functions are asterisked
> >
>
> Is there some work-around so I can have an S3 as.array() method in my
> package and avoid this warning?
>
>
>
--
Michael Friendly Email: friendly AT yorku DOT ca
Professor, Psychology Dept.
York University Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Street Web: http://www.datavis.ca
Toronto, ONT M3J 1P3 CANADA
More information about the R-devel
mailing list