Hi, is possible to make a R script to run under a console without open the R environment? Something like this example.R #!/usr/bin/R function(name="Put here your name") { print(name) } In a console I make ./example.R name="Ronaldo Reis J?nior" then program print my name. It is possible? Thanks Ronaldo -- A jury consists of twelve persons chosen to decide who has the better lawyer. -- Robert Frost --> Prof. Ronaldo Reis J?nior| .''`. UNIMONTES/Depto. Biologia Geral/Lab. Ecologia Evolutiva | : :' : Campus Universit?rio Prof. Darcy Ribeiro, Vila Mauric?ia | `. `'` CP: 126, CEP: 39401-089, Montes Claros - MG - Brasil | `- Fone: (38) 3229-8190 | chrysopa em gmail.com | ICQ#: 5692561 | LinuxUser#: 205366
On Mon, 2006-08-14 at 14:12 -0300, Ronaldo Reis-Jr. wrote:> Hi, > > is possible to make a R script to run under a console without open the R > environment? > > Something like this example.R > > #!/usr/bin/R > > function(name="Put here your name") { > print(name) > } > > In a console I make > ./example.R name="Ronaldo Reis J?nior" > then program print my name. > > It is possible? > > Thanks > RonaldoRonaldo, You might want to review these web pages: http://wiki.r-project.org/rwiki/doku.php?id=developers:rinterp http://kavaro.fi/mediawiki/index.php/Using_R_from_the_shell HTH, Marc Schwartz
Le 14.08.2006 19:12, Ronaldo Reis-Jr. a ?crit :> Hi, > > is possible to make a R script to run under a console without open the R > environment? > > Something like this example.R > > #!/usr/bin/R > > function(name="Put here your name") { > print(name) > } > > In a console I make > ./example.R name="Ronaldo Reis J?nior" > then program print my name. > > It is possible? > > Thanks > Ronaldo >Hi, take a look at that wiki page : http://wiki.r-project.org/rwiki/doku.php?id=developers:rinterp Cheers, Romain -- +-------------------------------------------------------------------+ | Romain FRANCOIS | | R Graph Gallery : http://addictedtor.free.fr/graphiques | `-------------------------------------------------------------------+
Em Seg 14 Ago 2006 17:58, Marc Schwartz (via MN) escreveu:> http://kavaro.fi/mediawiki/index.php/Using_R_from_the_shellI made a small change to the wrapper example by implementing dynamic allocation of memory and sizing the command line buffer to 32768 that is the real maximum size (at least under bash/sh :-). #include <stdio.h> /* file i/o functions */ #include <string.h> /* string functions */ #include <stdlib.h> /* malloc and exit codes */ /* * R_HOME has to be defined. Usually it is /usr/lib/R * todo: copy all command line params to R */ int main(int argc, char **argv) { /* should be enough for all */ char *cmd, l; FILE *out; /* without this "if" a segmentation fault will happen if no parameters are passed */ if(argc == 1) return(EXIT_FAILURE); /* dynamically allocates memory for command line buffer */ cmd=(char *)malloc(32768); /* assemble command line */ strcpy(cmd,"/usr/lib/R/bin/exec/R --vanilla --slave < "); strcat(cmd,argv[1]); /* do the real job */ out=popen(cmd,"r"); l = fgetc(out); printf("%c",l); while(l != EOF) { l = fgetc(out); if(l !=EOF) printf("%c",l); } /* cleanup: close files and free memory */ pclose(out); free((void *)cmd); return(EXIT_SUCCESS); } -- Alexandre Aguiar Independent consultant for medical research SPS Consultoria Voice: +55-11-9320-2046 Fax: +55-11-5549-8760