Re: [Rd] Inserting and testing revised functions in a package

From: Duncan Murdoch <>
Date: Thu, 09 Aug 2012 08:08:03 -0400

On 12-08-08 4:59 PM, Chris Warren wrote:
> Thanks, that was helpful in finding a bug in a library I was using, but now I'd
> like to run the original code (the revised code is unable to access some of the
> functions in the package, apparently, but I think I can work around it by
> running and checking the original function).
> How can I recover the original function? I tried using
> insertSource("SourceFileWithOriginalFunctionCode.R", package = "Package",
> functions = "functionOfInterest")
> but I run into the same inability to access some the package functions used by
> the function.
> I also tried reloading but got
> "The following object(s) are masked _by_ ‘.GlobalEnv’:
> probtrans"

When you reply to a message that is more than 2 years old, it's helpful to give some context.

Generally the reason a function can't see things in a package is because its environment is wrong. Since all functions in a package normally use the same environment, a simple fix is to put

environment(newfoo) <- environment(oldbar)

to copy the assignment of an unchanged function oldbar from the package to the new function you are trying to work with.

But the general way to "recover the original function" is just to restart R and attach the package.

Duncan Murdoch mailing list Received on Thu 09 Aug 2012 - 12:10:45 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 10 Aug 2012 - 19:50:39 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive