[R] developing package: dealing with namespaces

Vitalie Spinu spinuvit at gmail.com
Wed Feb 6 14:53:23 CET 2013


  >> Duncan Murdoch <murdoch.duncan at gmail.com>
  >> on Mon, 04 Feb 2013 13:23:57 -0500 wrote:

  DM> On 04/02/2013 12:59 PM, Ross Boylan wrote:
  >> I am tweaking an R package for which I have the source; the relevant code
  >> is in R not C.   I'm making changes to the package code.
  >> 
  >> What is the best workflow for doing this?  I recall the advice used to be
  >> to remove the NAMESPACE during development, but I don't think this is
  >> possible anymore.

[...]


  DM> I think the best workflow is to do the edits outside of R, and re-install the
  DM> package to test.

  DM> It is possible to do edits to a loaded package, using the assignInNamespace()
  DM> function, but I don't think there's a simple workflow that doesn't end up with
  DM> multiple copies of functions, and possible confusion over which version
  DM>   - is in the source, so will be saved
  DM>   - is in the global env, so will be executed by a user at the top level
  DM>   - is in the namespace, so will be executed by calls from other functions in
  DM> the namespace.

  DM> This is something that could probably be handled well by a smart editor.  I
  DM> don't know if any of the existing IDEs do it.

This is precisely what ess-developer is for.

Add a package to the list of developed packages with C-c C-t C-a. Now,
whenever you want to source your code into the package toggle the
developer mode on (C-c C-t C-t). After that, all ESS evaluation commands
(C-c C-c, C-M-x, C-c C-r, C-c C-l etc) will source your code
appropriately into the package environment/namespace. This also
correctly handles and re-installs all your modified S4 methods and
classes.

Here is the official doc:
http://ess.r-project.org/Manual/ess.html#Developing-with-ESS

    HTH, 
    Vitalie



More information about the R-help mailing list