[ESS] ESS R code evaluation in package

Vitalie Spinu @pinuvit @ending from gm@il@com
Thu Nov 8 23:32:26 CET 2018

>> On Tue, Nov 06 2018 16:53, Cyrus Harmon via ESS-help wrote:

> 1. How might I compile 'moose <- function () { “bar” }’ from Emacs/ESS and
> have moose show up in my package?
> 2. If it isn’t going into my package now, where is it going?

There are essentially 3 cases:

  1. `moose` is public (exported) function in your package. This means it is
  present in both namespace and package environments when the package is loaded.

  In this case, when you eval moose <- function() ... it goes into both package
  environment and namespace environment of the package.

  2. `moose` is not exported. This means it is in your namespace but not in the
  package environment. And ls("package:foo") wont show it .

  In this case when you eval `moose` it replaces the old version of `moose` in
  the namespace. You can see it with ls(asNamespace("foo"))

  3. Final case which (seems to be of main interest to you) when `moose` is a
  new function. Then, due to the fact that R namepsaces are sealed for new
  objects ESS has to do some cheating. It basically inserts a new environment
  between package namespace env and its parent and adds all new objects to that
  environment. You should get NEW[moose] message in the minibuffer.

  With this arrangement all your code will work as if that function exists in
  the actual package environment, but you won't be able to see that object with

> 3. If I can’t do this is there some easy way to build an reinstall an existing R
> library without having to call me R process and restart every time I want to
> make a simple change to a library function (this is where I find myself now).

Namespaced evaluation should work for R code as described above. If not, it's a

Alternatively you can use devtools integration. See C-c C-w map for what is
available. Particularly load-package with [C-c C-w l] or run complete re-install
and reload with (C-c C-w i). Depending on your version of ESS you might need the
dev version of devtools and friends to take the full advantage of the system.


More information about the ESS-help mailing list