From romain.francois at dbmail.com  Thu Sep  3 14:47:52 2009
From: romain.francois at dbmail.com (Romain Francois)
Date: Thu, 03 Sep 2009 14:47:52 +0200
Subject: [Rd] How to ship R scripts with R packages ?
In-Reply-To: <4A9FBAA3.1010606@stats.uwo.ca>
References: <4A9E4F3D.5070704@dbmail.com> <4A9E5356.4020907@stats.uwo.ca>
	<4A9FACDE.3020505@dbmail.com> <4A9FBAA3.1010606@stats.uwo.ca>
Message-ID: <4A9FBAF8.3060707@dbmail.com>

On 09/03/2009 02:46 PM, Duncan Murdoch wrote:
>
> On 03/09/2009 7:47 AM, Romain Francois wrote:
>> On 09/02/2009 01:13 PM, Duncan Murdoch wrote:
>>> Romain Francois wrote:
>>>> Hello,
>>>>
>>>> (This is a remix of this previous thread:
>>>> https://stat.ethz.ch/pipermail/r-devel/2009-August/054264.html , but
>>>> with a concrete example)
>>>>
>>>> I am developing some packages that contain scripts (for Rscript) and
>>>> would like to know what is the best/recommended way to ship these
>>>> scripts.
>>>>
>>>> An example is the "ant" package (R capable version of apache ant, see
>>>> http://tr.im/xHLs). The package has a ant.R script in the exec
>>>> directory and here is how I use it :
>>>>
>>>> $ `Rscript -e "cat( system.file( 'exec', 'ant.R', package = 'ant' )
>>>> ) " `
>>>>
>>>> ... not so pretty. Meanwhile, "Writing R extensions" talks about the
>>>> exec directory, but it is not clear if I can use it this way or how.
>>>>
>>> I think exec is a reasonable place to put the script. If you don't want
>>> to type that long command above, why not put it in a small function in
>>> the package? E.g. define
>>>
>>> antR <- function() cat( system.file( 'exec', 'ant.R', package = 'ant'
>>> ) )
>>>
>>> then you can run it with
>>>
>>> Rscript -e "ant::antR()"
>>>
>>> Duncan Murdoch
>>
>> I've implemented a minimal version of this in package "exec". For
>> example.
>>
>> $ Rscript -e "exec::rscript( 'ant', 'ant.R')"
>>
>> Romain
>>
>> btw, exec is maintained at r-forge :
>>
>> $ svn checkout svn://svn.r-forge.r-project.org/svnroot/highlight/pkg/exec
>
> That's a nice, simple function. I might add an argument
>
> dir = "exec"
>
> rather than hard-coding that directory choice; others might keep their
> scripts somewhere else, or want to run one of the test scripts, etc.
>
> Duncan Murdoch

Good point. The other hard coded thing is that it goes looking for the 
path of Rscript, which might not be that useful if the script is a 
python/perl/ script.

I might try to encapsulate an R equivalent to !/bin/env lookup ...

-- 
Romain Francois
Professional R Enthusiast
+33(0) 6 28 91 30 30
http://romainfrancois.blog.free.fr
|- http://tr.im/xMdt : update on the ant package
|- http://tr.im/xHLs : R capable version of ant
`- http://tr.im/xHiZ : Tip: get java home from R with rJava



[Rd] How to ship R scripts with R packages ?
Romain Francois