Re: [R] source a specific function

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon, 18 Jun 2007 12:30:19 -0400

  1. You can do this:

> library(plotrix)
> environment(draw.arc) <- .GlobalEnv # implicitly copies it
> detach()
> plot(1,1)
> draw.arc(1, 1, .1) # its there

2. Since the local environment we created in the prior post was anonymous and since there are no other references to it either I assume it gets deleted on the next garbage collection automatically.

On 6/18/07, Ted Harding <ted.harding_at_nessie.mcc.ac.uk> wrote:
> On 18-Jun-07 14:28:35, Gabor Grothendieck wrote:
> > This loads all the functions into an anonymous environment defined
> > by local and then exports f to the global environment.
> >
> > f <- local({
> > source("/a.R", local = TRUE)
> > environment(f) <- .GlobalEnv
> > f
> > })
>
> That looks neat! Two questions:
>
> 1. Would something similar work for extracting selected functions
> from a library (assuming that you know about interdependencies)?
>
> E.g. something like
>
> f <- local({
> library(f.etc.lib)
> environment(f) <- .GlobalEnv
> f
> })
>
>
> 2. Having done what you describe to extract just f from a source
> file, can one then "delete" the local environment used to load
> the source? I think what I'm basically asking is whether the
> exporting is done "by value" (local environment deletion OK)
> or "by reference" (deletion would destroy the exported object).
>
> Apologies, but for instance "?local" is a bit too deep for me!
>
> The underlying agenda behind these queries is the saving of
> memory space.
>
> With theanks,
> Ted.
>
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <ted.harding_at_nessie.mcc.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 18-Jun-07 Time: 17:11:15
> ------------------------------ XFMail ------------------------------
>
> ______________________________________________
> R-help_at_stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



R-help_at_stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon 18 Jun 2007 - 16:33:02 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 Mon 18 Jun 2007 - 17:32:03 GMT.

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