[R] "#!/usr/bin/R"

Don MacQueen macq at llnl.gov
Mon May 10 22:59:07 CEST 2004


That someone might have been me; I did at one time figure out how to 
execute scripts based on a first line like that of the subject line 
of this thread.

As I recall, what I did was
   1) before attempting to execute a script having such a first line, 
define the env vars that R.bin needs
   2) specify R.bin, rather than R, on that first line.

I have only a very shallow understanding of how the OS interprets and 
executes such scripts, but I believe that it doesn't work when the 
file being pointed to (/usr/bin/R in this case) is a shell script. It 
has to be an executable binary. Hence, the env vars that R.bin needs, 
that are set in the "R" shell script, need to be manually defined 
first (or in a user's shell startup script such as .tcshrc, or in a 
webserver's configuration files).

Associated with that attempt was a modification of the sources that I 
made, commenting out two lines in system.c, specifically:

See file ./source/src/unix/system.c
line 239 in R-1.8.1 patched as of 12/3/03
             snprintf(msg, 1024, "ARGUMENT '%s' __ignored__\n", *av);
             R_ShowMessage(msg);

This was because I wanted to use R for cgi scripts, and that warning 
message preceded the html headers that, according to html 
specifications, *must* come first. Otherwise the broswer chokes.

If I recall correctly, that modification is not necessary simply to 
create and run such scripts. Only in the context of using R as a cgi 
engine did I find it necessary.

Of course, there may have been a better way, or there may be a better 
way now, but that is what I found at the time.

-Don

At 12:26 PM -0400 5/10/04, Liaw, Andy wrote:
>Someone had modified the R source to handle this, but it has not been
>incorporated into the official R source, if I'm not mistaken.  Search the
>R-devel archive.
>
>HTH,
>Andy
>
>>  From: Webb Sprague
>>
>>  Hi all,
>>
>>  Is there any documentation on running R like one would run a shell or
>>  Perl script, with out/input directed appropriately,
>>  environment variable
>>  access, and command switch processing?
>>
>>  I looked some, and even remembered to check the FAQ, but
>>  couldn't find
>>  anything.
>>
>>  Thanks
>>  W
>
>
>------------------------------------------------------------------------------
>Notice:  This e-mail message, together with any attachments,...{{dropped}}
>
>______________________________________________
>R-help at stat.math.ethz.ch mailing list
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html


-- 
--------------------------------------
Don MacQueen
Environmental Protection Department
Lawrence Livermore National Laboratory
Livermore, CA, USA




More information about the R-help mailing list