From atp at piskorski.com  Sat Sep  5 13:15:11 2009
From: atp at piskorski.com (Andrew Piskorski)
Date: Sat, 5 Sep 2009 07:15:11 -0400
Subject: [Rd] Load a package without installing it
In-Reply-To: <f8e6ff050909040639r35659a8hd00d06901093dcd1@mail.gmail.com>
References: <f8e6ff050909040639r35659a8hd00d06901093dcd1@mail.gmail.com>
Message-ID: <20090905111511.GA47877@piskorski.com>

On Fri, Sep 04, 2009 at 08:39:12AM -0500, Hadley Wickham wrote:

> When developing a package, it's often useful to be able to reload it,
> without re-installing, re-starting R and re-loading.

Why would you ever need to restart R in such a situation?

What I do is make the code change in my package, build it from source
like so:

  R CMD INSTALL $r_lazy_arg -l ../R $Library

and then detach and re-attach it in my R session with:

  detach("package:my.pkg") ; library(my.pkg, lib.loc="/home/me/my-R-stuff/R")

That's it.  Works fine as long as your package doesn't use namespaces;
an additional command is necessary to handle namespaces but I forget
what it is.  Works fine for packages with C code too, as long as
you've correctly set up your package's .First.lib() and .Last.lib()
your to call library.dynam() library.dynam.unload().

I'm not sure whether the detach() will play nicely with package
dependencies, as I've found them annoying in other circumstances and
so tend to never use package dependencies in my code.

It'd be nice not to have to "compile" the R code at the command line
all the time and instead just have R read my source files from their
original location when I call library(), but the above isn't bad.

> To do this I've
> written a little script that inspects the package description and
> loads dependencies, data and code - http://gist.github.com/180883.
> It's obviously not very general (being tailored to my description
> files) and won't work for packages containing C code, but I hope you
> might find it useful nonetheless.

source() and load() both dump code into your top-level workspace,
right?  When I'm developing a package, I'd generally rather have R
access my package's stuff via the search path in the usual manner, not
from some other special location that Production never uses.

-- 
Andrew Piskorski <atp at piskorski.com>
http://www.piskorski.com/



[Rd] Load a package without installing it
Andrew Piskorski