Re: [Rd] Lightweight 'package' idea.

From: hadley wickham <h.wickham_at_gmail.com>
Date: Wed, 20 Jan 2010 08:23:03 -0600

On Fri, Aug 21, 2009 at 6:03 AM, Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk> wrote:
> I'm often wanting to develop functions whilst manipulating data. But I
> don't want to end up with a .RData full of functions and data. It
> might be that I have functions that are re-usable but not worth
> sticking in a package.
>
>  So I've tried to come up with a paradigm for function development
> that more closely follows the way Matlab and Python do it (partly
> inspired by a confused Matlab convert over on R-help).
>
>  My requirements were thus:
>
>  * .R files as the master source for R functions
>  * Don't see the functions in ls()
>  * After editing R, make it easy to update the definitions visible to
> R (unlike rebuilding and reloading a package).
>
>  So I wrote these two in a few mins:
>
> loadDir <- function(dir){
>  e = attach(NULL,name=dir)
>  assign("__path__",dir,envir=e)
>  reloadDir(e)
>  e
> }
>
> reloadDir <- function(e){
>  path = get("__path__",e)
>  files = list.files(path,".R$",full.names=TRUE,recursive=TRUE,ignore.case=TRUE)
>  for(f in files){
>    sys.source(f,envir=e)
>  }
> }

Rather than using __path__, why not just use chdir = TRUE in sys.source() and rely on the usual R working directory semantics?

>  Sourcing everything on any change seems a bit wasteful, but until R
> objects have timestamps I can't think of a better way. Hmm, maybe my
> environment could keep a __timestamp__ object... Okay, this is getting
> less simple now...

That's what I do for all of my packages during development. You really need a huge amount of code before it starts to take a noticeable amount of time.

Hadley

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

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Wed 20 Jan 2010 - 14:35:33 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 20 Jan 2010 - 19:40:15 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive