Dear R-persons,
In the past (and still) I rely rather much on weights() function in
package vegan. Several vegan objects have weights which are queried and
used. Many of the utilities were written so that they can be used
similarly with non-vegan methods. My strategy was to query weights(),
and if the object did not have those, the utility found NULL weights and
knew how to handle them (i.e., not use weights). A typical usage in
vegan is:
if (is.null(w))
w <- rep(1, nrow(x))
This seems to be broken in R 2.7.0 which stops with error if an object
does not have weights. If there is no specific weights() method, the
command is relegated to stats:::weights.default which is written like
this:
> stats:::weights.default
function (object, ...)
naresid(object$na.action, object$weights)
<environment: namespace:stats>
and with an arbitrary object the error is:
> weights(ord)
Error in object$na.action : $ operator is invalid for atomic vectors
To me stats:::weights.default does not look like a default function, but
a function that expects a very specific input object with items
na.action and weights (and both are rare and very specific). A more
natural choice would be:
weights.default <- function(object, ...) NULL
or a function that returns NULL if there are no weights. In R 2.6.2 the
operation was this de facto, since NULL was returned anyway.
Is there a way to circumvent this feature? (It is a "feature" because
it
is designed to work like this).
cheers, jari oksanen
--
Jari Oksanen <jari.oksanen at oulu.fi>