Thanks Joshua for your prompt reply, and my apologies for my much delayed one. I've only just been able to come back to this.
I need the epicalc package for the pyramid function, and so it seems I do have to load the package. I've contacted the package maintainer but in the meantime I've taken up and used your suggestion to create a method that "overrides" aggregate.numeric: aggregate.numeric <- function(x, ...) { aggregate.default(x, ...) } And it works swell. Thank-you for the excellent tip! -----Original Message----- From: Joshua Wiley [mailto:jwiley.ps...@gmail.com] Sent: Wednesday, 2 November 2011 8:34 p.m. To: Oliver Mannion (COMPASS) Cc: r-help@r-project.org Subject: Re: [R] Removing or ignoring package version for generic function in locked environment 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) Good luck, Josh On Nov 1, 2011, at 17:31, "Oliver Mannion (COMPASS)" <o.mann...@auckland.ac.nz> wrote: > Hi, > > 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, > > Oliver > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.