[ESS] r-related question: editing NAMESPACEd functions in packages

Martin Maechler maechler at stat.math.ethz.ch
Mon Nov 7 21:35:39 CET 2011


On Mon, Nov 7, 2011 at 19:51, Steve Lianoglou
<mailinglist.honeypot at gmail.com> wrote:
> Hi,
>
> In addition to what Gavin suggests below, you could consider using
> Hadley's devtools package:
>
> https://github.com/hadley/devtools
>
> It's meant to help make authoring packaging easier ... on thing it can
> do is reload your package from its source tree w/ proper handling of
> redefined functions in your dev-package namespace.

but it says itself that it's very opiniated about package development, notably
asking you to use roxygen(2) instead of editing *.Rd files....
not something I'd like to even start considering, even less given the
new nice ess-help mode we will have soon.

As Stephen said initially, this topic is really about R,..
so here is my own approach that I've been using for a while:

    attach(asNamespace("package:......"))

makes the full namespace of the package available at position  2,
so all the hidden functions are visible to every function that I
"source" into globalenv(), i.e., where
I use the usual "ess-eval-function" etc functions .. such that the
fixed/changed functions/objects all come before the ones at position
2..

Also, I've long turned off the silly  "save workspace (y/n/..) ?'"
question, and so
  M-C-q M-x R

  (kill R and restart it -- inside the *same* *R* buffer .. hence with
"history"(in a general Emacs-like    sense))

is also quite fast and often done..

Martin
>
> In particular, I guess you'd be interested in the `load_all` and
> perhaps `install` functions (with brief outlines in that README on the
> landing page)
>
> HTH,
> -steve
>
> On Mon, Nov 7, 2011 at 6:44 AM, Gavin Simpson <ucfagls at ucl.ac.uk> wrote:
>> On Mon, 2011-11-07 at 11:03 +0000, Stephen Eglen wrote:
>>> My turn to ask a question ...  it is mostly r-related, but does have an ESS
>>> twist.
>>>
>>> None of my own R packages have ever had a NAMESPACE file, so I could
>>> load the package, then dynamically edit its functions and re-eval it in
>>> ESS just with ess-eval-defun.
>>>
>>> R 2.14.0 now seems to require NAMESPACE files.  So, if I now want to
>>> edit and re-eval a function f in my package p, do I have to reload my
>>> package, rather than just do ess-eval-defun on the function f?  (I think
>>> just doing ess-eval-defun on the source code for f will then create two
>>> versions of my function, one in global environment, and one in p::f)
>>>
>>> Are there any tips for keeping the edit-run cycle short when editing
>>> functions in NAMESPACE'd packages?
>>
>> See ?assignInNamespace
>>
>> If you have f in global environment that is an edited version of p:::f
>> then
>>
>> assignInNamespace("f", f, "p")
>>
>> will effectively do
>>
>> p:::f <- f
>>
>> so that if you call p:::f you get the modified f not the one originally
>> defined in the NAMESPACE of p. If you rm(f) from the global env then you
>> can work as before but using the new f and not the one defined in the
>> package as run-time.
>>
>> G
>>
>>>
>>> Stephen
>>>
>>> ______________________________________________
>>> ESS-help at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/ess-help
>>>
>>
>> --
>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>>  Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
>>  ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
>>  Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
>>  Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
>>  UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
>> %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
>>
>> ______________________________________________
>> ESS-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/ess-help
>>
>
>
>
> --
> Steve Lianoglou
> Graduate Student: Computational Systems Biology
>  | Memorial Sloan-Kettering Cancer Center
>  | Weill Medical College of Cornell University
> Contact Info: http://cbio.mskcc.org/~lianos/contact
>
> ______________________________________________
> ESS-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/ess-help
>
>



More information about the ESS-help mailing list