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

Gavin Simpson ucfagls at ucl.ac.uk
Mon Nov 7 12:44:07 CET 2011


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
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the ESS-help mailing list