From MEC at stowers.org  Thu Sep 22 15:29:19 2011
From: MEC at stowers.org (Cook, Malcolm)
Date: Thu, 22 Sep 2011 08:29:19 -0500
Subject: [Rd] using R as SHELL in gnu make
In-Reply-To: <6441154A9FF1CD4386AF4ABF141A056D2A7502B2@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
References: <2C40E43D1F7A56408C4463FD245DDDF9856C3218@EXCHMB-02.stowers-institute.org>
	<6441154A9FF1CD4386AF4ABF141A056D2A7502B2@WMEXOSCD2-N1.bocad.bank-banque-canada.ca>
Message-ID: <2C40E43D1F7A56408C4463FD245DDDF9856C3577@EXCHMB-02.stowers-institute.org>

OK,

I now have a working version of setting SHELL=R in a GNU make script, allowing make?s recipes to be written in R, that works out most of the complications.

I plan to clean it up a little more and blog about it soon here: http://malcook-gedanken.blogspot.com/ - I?ll follow up here  when I do.

The approach optionally allows evaluating the recipes using a running Rserve (http://rosuda.org/Rserve/), avoiding initialization time and allowing pre-loading of R libraries common to multiple recipes.

The approach however does NOT provide any special mechanism to preserve state between recipes, 
Rather, recipes may create the make rule?s target as a state dump by setting with `file=?$@?`  in a call to `save` (or `save.image`, `dump`, as desired).  
Other make rules may then call `load('$<')` when the previously saved dump is a pre-requisite to the rule.

I?m still not sure if it is not more of an amusement and am interested in all thoughts on this, and welcome any suggestions for example applications that I might include when I go to blog it up...

Cheers,

~Malcolm


-----Original Message-----
From: Paul Gilbert [mailto:pgilbert at bank-banque-canada.ca] 
Sent: Tuesday, September 20, 2011 8:32 AM
To: Cook, Malcolm; 'help-make at gnu.org'; 'r-devel at r-project.org'
Subject: RE: using R as SHELL in gnu make

Other than the RServe part, I do this all the time. It works well. Perhaps we can put together some notes off-line and then bring it back to the list.

Paul

> -----Original Message-----
> From: r-devel-bounces at r-project.org [mailto:r-devel-bounces at r-
> project.org] On Behalf Of Cook, Malcolm
> Sent: September 19, 2011 6:35 PM
> To: 'help-make at gnu.org'; 'r-devel at r-project.org'
> Subject: [Rd] using R as SHELL in gnu make
> 
> I am intrigued by the possibility of using R as the SHELL in a (Gnu)
> makefile (instead of /bin/sh).  (c.f.
> http://www.gnu.org/software/make/manual/make.html#Choosing-the-Shell)
> 
> Well, rather, I would like the makefile's SHELL to be a command which
> communicated with an R process.
> 
> The makefile targets/prerequistes would, as always, be OS files, which
> would be written/read using standard R file IO.
> 
> The makefile's "recipe"s would be written in R (instead of the usual
> shell).
> 
> The R process would be able to be initiated by `load`ing one or more R
> datasets, libraries or entire images.
> 
> The R process would be able to accumulate state as the makefile
> progressed.  The recipe's would be able to refer to that state,
> allowing conditional execution.
> 
> The R process would optionally be saved as an image of on job
> termination/completion.
> 
> The R process might be managed using the RServe package, and would need
> to be initiated once only, when the makefile was first invoked.
> 
> I would appreciate learning if anyone had any success, informative
> failures, or other lore that may help in (or dissuade me from)
> embarking on attempt this.
> 
> Thanks,
> 
> Malcolm Cook
> Stowers Institute for Medical Research
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
====================================================================================

La version fran?aise suit le texte anglais.

------------------------------------------------------------------------------------

This email may contain privileged and/or confidential information, and the Bank of
Canada does not waive any related rights. Any distribution, use, or copying of this
email or the information it contains by other than the intended recipient is
unauthorized. If you received this email in error please delete it immediately from
your system and notify the sender promptly by email that you have done so. 

------------------------------------------------------------------------------------

Le pr?sent courriel peut contenir de l'information privil?gi?e ou confidentielle.
La Banque du Canada ne renonce pas aux droits qui s'y rapportent. Toute diffusion,
utilisation ou copie de ce courriel ou des renseignements qu'il contient par une
personne autre que le ou les destinataires d?sign?s est interdite. Si vous recevez
ce courriel par erreur, veuillez le supprimer imm?diatement et envoyer sans d?lai ?
l'exp?diteur un message ?lectronique pour l'aviser que vous avez ?limin? de votre
ordinateur toute copie du courriel re?u.


[Rd] using R as SHELL in gnu make
Cook, Malcolm