Load a package without installing it

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Load a package without installing it

Hadley Wickham-2
Hi all,

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

Any comments would be appreciated.

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Load a package without installing it

Romain Francois
On 09/04/2009 03:39 PM, Hadley Wickham wrote:

>
> Hi all,
>
> When developing a package, it's often useful to be able to reload it,
> without re-installing, re-starting R and re-loading.  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.
>
> Any comments would be appreciated.
>
> Hadley

Nice. I would guess many of us would have versions of this, it would be
good to formalise it so that it could deal with :
- namespaces, you might want your unexported functions to be separate
from your exported functions. It looks like your function loads
everything into .GlobalEnv
- S4 objects, what would happen if you re-source the definition of an S4
class and continue to manage objects created before the resourcing

Romain

--
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/xMdt : update on the ant package
|- http://tr.im/xHLs : R capable version of ant
`- http://tr.im/xHiZ : Tip: get java home from R with rJava

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Load a package without installing it

Hadley Wickham-2
> Nice. I would guess many of us would have versions of this, it would be good
> to formalise it so that it could deal with :
> - namespaces, you might want your unexported functions to be separate from
> your exported functions. It looks like your function loads everything into
> .GlobalEnv
> - S4 objects, what would happen if you re-source the definition of an S4
> class and continue to manage objects created before the resourcing

I use neither namespaces nor S4, so it's no suprise my code doesn't
handle them ;)

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Load a package without installing it

Gabor Grothendieck
In reply to this post by Hadley Wickham-2
This is sufficiently useful that it would be nice to have it
as part of R itself.  For the moment, perhaps you could
make a package of it on CRAN or contribute it to some
other existing CRAN package.

On Fri, Sep 4, 2009 at 9:39 AM, Hadley Wickham<[hidden email]> wrote:

> Hi all,
>
> When developing a package, it's often useful to be able to reload it,
> without re-installing, re-starting R and re-loading.  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.
>
> Any comments would be appreciated.
>
> Hadley
>
> --
> http://had.co.nz/
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Load a package without installing it

Andrew Piskorski
In reply to this post by Hadley Wickham-2
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 <[hidden email]>
http://www.piskorski.com/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: Load a package without installing it

Hadley Wickham-2
On Sat, Sep 5, 2009 at 6:15 AM, Andrew Piskorski<[hidden email]> wrote:
> 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?

Two comments:

 * running install is slower than just sourcing all the code

 * detach specifically warns against the use you make of it: "So
detaching and re-attaching a package may not refresh some or all
components of the package, and is inadvisable."

But if it works for you, great!

> 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.

This seems a bit extreme!

Hadley

--
http://had.co.nz/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel