From pgilbert902 at gmail.com  Fri May 25 23:24:34 2012
From: pgilbert902 at gmail.com (Paul Gilbert)
Date: Fri, 25 May 2012 17:24:34 -0400
Subject: [Rd] equivalent to source() inside a package
In-Reply-To: <CADhXZziobLnoQpSmkVLg55gkcFdnk-2NbZQUTizXr+edX1DPJg@mail.gmail.com>
References: <CADhXZziobLnoQpSmkVLg55gkcFdnk-2NbZQUTizXr+edX1DPJg@mail.gmail.com>
Message-ID: <4FBFF892.1030203@gmail.com>

Is there a reason for not using a vignette or putting a file in the 
demo/  directory?  This seems like the sort of thing for which they are 
intended.

Paul

On 12-05-25 03:33 PM, Wei Hao wrote:
> 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
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel



[Rd] equivalent to source() inside a package
Paul Gilbert