From ggrothendieck at gmail.com  Mon Oct  3 17:56:37 2016
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Mon, 3 Oct 2016 11:56:37 -0400
Subject: [Rd] On implementing zero-overhead code reuse
In-Reply-To: <CAFvQaj4Bcd-FW_z2Sc019d9JUa_Xy3Xz0HO=Ze16ZLnGJx4JiQ@mail.gmail.com>
References: <CAFvQaj4Bcd-FW_z2Sc019d9JUa_Xy3Xz0HO=Ze16ZLnGJx4JiQ@mail.gmail.com>
Message-ID: <CAP01uRnTUvLxEAXaCk-2-WofF=+bS=1Udw2+Gh_ph3ckB40EhA@mail.gmail.com>

Have a look at the CRAN modules package and the import package.

On Sun, Oct 2, 2016 at 1:29 PM, Kynn Jones <kynnjo at gmail.com> wrote:
> I'm looking for a way to approximate the "zero-overhead" model of code
> reuse available in languages like Python, Perl, etc.
>
> I've described this idea in more detail, and the motivation for this
> question in an earlier post to R-help
> (https://stat.ethz.ch/pipermail/r-help/2016-September/442174.html).
>
> (One of the responses I got advised that I post my question here instead.)
>
> The best I have so far is to configure my PROJ_R_LIB environment
> variable to point to the directory with my shared code, and put a
> function like the following in my .Rprofile file:
>
>     import <- function(name){
>         ## usage:
>         ## import("foo")
>         ## foo$bar()
>         path <- file.path(Sys.getenv("PROJ_R_LIB"),paste0(name,".R"))
>         if(!file.exists(path)) stop('file "',path,'" does not exist')
>         mod <- new.env()
>         source(path,local=mod)
>         list2env(setNames(list(mod),list(name)),envir=parent.frame())
>         invisible()
>     }
>
> (NB: the idea above is an elaboration of the one I showed in my first post.)
>
> But this is very much of an R noob's solution.  I figure there may
> already be more solid ways to achieve "zero-overhead" code reuse.
>
> I would appreciate any suggestions/critiques/pointers/comments.
>
> TIA!
>
> kj
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



[Rd] On implementing zero-overhead code reuse
Gabor Grothendieck