[R] Removing or ignoring package version for generic function in locked environment
jwiley.psych at gmail.com
Wed Nov 2 08:34:10 CET 2011
Interesting. I have a few (untested) thoughts. Before I get into those though, this seem to me like a case where contacting either the maintainer of epicalc or of the functions not under your control that give warnings. I think either would be appropriate because if the default method works correctly with no error, I really do not think aggregate.numeric should give a warning. The onus seems somewhat on the writer of methods for classes as common as numeric to write something that works. That said, without any idea what it is being used on there are endless possibilities for why a warning is being generated. But supposing neither of those are options, here are some ideas.
1) if you happen to be using this in your own package, try just importing aggregate numeric, rather than fully loading the epicalc package.
2) create a method that mimics aggregate but is for numeric, and make sure it is in an environment between the out of control functions and epicalc so it is called rather than epicalcs version.
3) use epicalc and then unload it rather than just removing that function (may not fly)
4) copy the epicalc aggregate numeric and just use that code and never load the package
5) you may be able to unlock() the name space so you can remove the methods (I think the function is unlock but there may be caps somewhere in there)
6) if the offending functions have a class that is not numeric but inherits from numeric, you could write a method for their particular class that would then supersede the inherited numeric method
All of these are highly unsatisfactory in one way another. I am not in a position to test anything out at the moment (iPhone, well that's not true, I could ssh to my cluster, start r there and try via the terminal but that is truly painful on a phones keyboard)
On Nov 1, 2011, at 17:31, "Oliver Mannion (COMPASS)" <o.mannion at auckland.ac.nz> wrote:
> I use the epicalc package which provides the function aggregate.numeric.
> Unfortunately aggregate.numeric produces warnings when aggregate is used by functions not under my control on a numeric value. If I don't load epicalc, aggregate.default is used instead by these functions and does not produce any warning.
> However I need epicalc. So to get around this, what I would do is firstly remove aggregate.numeric:
> rm(aggregate.numeric, pos=which(search() == "package:epicalc"))
> This worked fine in R 2.13.1. However in R 2.14.0 I am getting the following:
> Error in rm(aggregate.numeric, pos = which(search() == "package:epicalc")) :
> cannot remove bindings from a locked environment
> Is there some way I can remove aggregate.numeric, or otherwise prevent it from being used?
> Thanks in advance,
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help