[Rd] equivalent to source() inside a package

Wei Hao whao at princeton.edu
Fri May 25 21:33:04 CEST 2012


Hi all:

I'm working on a project that I have packaged for ease of
distribution. The different simulations in the package share code, so
obviously I have those parts organized as functions. Now, I want to
show people my code, but the structure with the internal functions
might be a little confusing to follow. One thing I tried was to have
the code of the functions as their own R files in the R/ folder, and
then using source() instead of calling the functions (with consistent
variable names and such) but this didn't work. The goal is for the
user to be able to see the entirety of the code in the interactive R
session, i.e. with a standard package implementation:

> library(wei.simulations)
> sim1
function (seed=5555)
{
    [stuff]
    a = internal_function1(data)
    [stuff]
}



I would like the user to see:

> sim1
function (seed=5555)
{
    [stuff]
    tmp = apply(data,1,mean)
    a = sum(tmp) #or whatever, this is just an example
    [stuff]
}

where I can change those two lines in their own file, and have the
changes apply for all the simulation functions. I know this seems like
a weird question to ask, but it would be useful for me to make it as
foolproof as possible for the user to see all the simulation code (I'm
presuming the user is a casual R user and not familiar with looking
through package sources).

Thanks
Wei



More information about the R-devel mailing list