From sfalcon at fhcrc.org  Sat Aug 18 19:41:05 2007
From: sfalcon at fhcrc.org (Seth Falcon)
Date: Sat, 18 Aug 2007 10:41:05 -0700
Subject: [Rd] Overriding S4 methods in an installed package
In-Reply-To: <200708172217.l7HMHG6a025509@mcintosh.research.telcordia.com>
	(Allen McIntosh's message of "Fri\, 17 Aug 2007 18\:17\:16 -0400")
References: <200708172217.l7HMHG6a025509@mcintosh.research.telcordia.com>
Message-ID: <m28x88u4em.fsf@fhcrc.org>

Allen McIntosh <mcintosh at research.telcordia.com> writes:

> Is it possible to override S4 methods in an installed package?
> The naive
>
> library("pkg")
> setMethod("foo", signature(obj = "bar"),
>         function(obj , x, y) { new definition }
> 	, where="package:pkg")
>
>
> results in the error
>
> Error in setMethod("foo", signature(obj = "bar"), function(obj,  :
>         the environment "pkg" is locked; cannot assign methods for function "foo"
>
> (This is from R 2.5.1 on Fedora Core 5, if that matters)
>
> Background:  A colleague claims to have found an error in a package.
> He and I would prefer to do some experimentation before contacting
> the authors.  Subclassing is the "correct" way to do this, and I
> expect we will eventually subclass for other reasons, but I was
> wondering if an override was possible and easier.

If foo is a generic that you are calling directly, then you can
probably define it in the global environment (omit the where arg) and
test it that way.

OTOH, if foo is used by pkg internally, then it will be much easier to
simply edit the source for pkg, reinstall and test.  If you find and
fix a bug, most package maintainers will be quite happy to integrate
your fix.

+ seth

-- 
Seth Falcon | Computational Biology | Fred Hutchinson Cancer Research Center
BioC: http://bioconductor.org/
Blog: http://userprimary.net/user/



[Rd] Overriding S4 methods in an installed package
Seth Falcon