From whao at princeton.edu  Fri May 25 21:33:04 2012
From: whao at princeton.edu (Wei Hao)
Date: Fri, 25 May 2012 15:33:04 -0400
Subject: [Rd] equivalent to source() inside a package
Message-ID: <CADhXZziobLnoQpSmkVLg55gkcFdnk-2NbZQUTizXr+edX1DPJg@mail.gmail.com>

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



[Rd] equivalent to source() inside a package
Wei Hao