0

I have a function that is part of my own package. When called from namespace:package_name, the function behaves slightly different than when it is called from R_GlobalEnv. To find out why I want to debug the function.

To make debugging the function as easy as possible, I want to write the changes I made to the function to the namespace:package_name environment, so I can immediately test it, but I cannot figure out how to do this.

If I type namespace:package_name, it gives the environment at the bottom as follows:

<bytecode: 0x00000236403c9da0>
<environment: namespace:package_name>

But if I try environment(fun) <- namespace:package_name, it says:

Error: object 'namespace' not found.

How do I set the environment of my function to the package environment?

EDIT:

Surprisingly fixInNamespace does not leave the namespace intact.

Tom
  • 2,173
  • 1
  • 17
  • 44
  • I'm not sure I got it right but, can't you reinstall it (a git branch perhaps) with the changes applied? – Claudio Paladini May 19 '22 at 07:05
  • 1
    @Paladinic Of course, but this is what I am trying to circumvent.. – Tom May 19 '22 at 07:21
  • `pacman:p_temp` might work, I haven't tried it for a package I've already got installed though - https://www.rdocumentation.org/packages/pacman/versions/0.5.1/topics/p_temp. It works by installing the package in to a temporary directory that's then removed after the session is over – Jonny Phelps May 19 '22 at 07:58
  • 1
    Does this answer your question? [Add objects to package namespace](https://stackoverflow.com/questions/3094232/add-objects-to-package-namespace) – Claudio Paladini May 19 '22 at 11:37

0 Answers0