[R] editing a package directly from R

Martin Maechler maechler at stat.math.ethz.ch
Tue Dec 28 14:55:16 CET 2004


>>>>> "UweL" == Uwe Ligges <ligges at statistik.uni-dortmund.de>
>>>>>     on Tue, 28 Dec 2004 13:12:49 +0100 writes:

    UweL> Fredrik Lundgren wrote:
    >> Dear R,
    >> 
    >> I have made a package 'myfuncs' of some home made
    >> functions and installed it without problems. It contains
    >> no C or fortran code and no dynamic link library. Is
    >> there a way to edit this package directly from R (or
    >> Xemacs with ESS) or do I always have to edit the source
    >> and then reinstall the package?

    UweL> The latter.

yes, edit the source by all means, but
no, you don't have to reinstall the package every time if you
are working on the package itself!

I do +- the following (on Unix; Windows should be close: use
		      'Rcmd' instead of "R CMD"):
1) a) If you are using a namespace, rename the "NAMESPACE" file to
      "NAMESPACE-" (e.g.), "R CMD check myfuncs" which installs
      a "no-namespace version" of the package into myfuncs.Rcheck
      {{and now gives warnings for all `namespace - private'
        objects that are not documented}}
   b) otherwise, just 'R CMD check myfuncs'

2) library(myfuncs, lib = "<correct_path_to>/myfuncs.Rcheck")
  
   You have all your current definitions available in *R*
   {assuming ESS}.

3) Now open the >> source << file you want to work on, say
    ....../myfuncs/R/onefun.R
   and use ESS (e.g. C-c C-l) to load the file/ or just the
   changed code into your R session.

   Test out your changes / improvements etc,
   always editing the source and sending its current contents to R.

4) Once you think you have ``done a batch'' (whatever that will mean).
   Run again  "R CMD check myfuncs" which uses your new changed
   source but also runs all other examples and the tests in
   myfuncs/tests/*.R  etc.

5) detach("package:myfuncs")  and   `` go to 2) ''

6) If you are finished with your changes, you'll want to rename
   "NAMESPACE-" back to "NAMESPACE".
    {you will typically be reminded because of 'R CMD check's warnings}.

Martin Maechler, ETH Zurich

    >> I have a weak memory that such editing could be done in
    >> S-Plus 2000 or 6.1?  Windows XP, R 2.0.1, Xemacs 21.4.13,
    >> and ESS 5.2.2
    >> 
    >> Thanks for any help
    >> 
    >> Fredrik Lundgren




More information about the R-help mailing list