Moumita Das
2009-Nov-11 13:25 UTC
[R] Passing MULTIPLE arguments from php file to r scripts
Hi friends, Again i don't know how to pass multiple arguments from php file to r scripts. Please have a look at this link ; it gives a very simple explanation of passing variables from a PHP page to r scipts.Because i have done the same thing. http://www.math.ncu.edu.tw/~chenwc/R_note/index.php?item=php&subitem=ex_1<http://www.math.ncu.edu.tw/%7Echenwc/R_note/index.php?item=php&subitem=ex_1> *CONTENTS OF MY PHP FILE: ex_1.php* <?php** $cmd = "echo 'argv1 <- \"ex_1.R\"; source(argv1)' | " . "/usr/bin/R --vanilla --slave "; $ret = system($cmd); ?> Assigned the file name to argv1 and passed argv1 to source() function for running r scripts *CONTENTS OF MY R FILE: ex_1.r* print("hello") print(argv1) When I open the php file in the browser I get these results:--- [1] "hello" [1] "ex_1.R" See here the php file could invoked the desired r script as well as pass the argument argv1 from the php file and made it available to the r script Till passing of one argument everything was fine. *Then I changed the php file ex_1.php:---* <?php** $a=1; $cmd = "echo 'argv1 <- \"ex_1.R\"; source(argv1)' | " . "/usr/bin/R --vanilla --slave "; //print($cmd); $ret = system($cmd); ?> *Then I changed the r script ex_1.r:---* print("hello") print(argv1) print(argv2) When I ran the php file neither the php file could invoke the r script nor the arguments got printed(none of the arghuments got printed,not even argv1 ) So with this change in $cmd :-- $cmd = "echo 'argv1 <- \"ex_1.R\"; source(argv1)' | " ."echo 'argv2 <-".$a."; source(argv1)' | " ."/usr/bin/R --vanilla --slave"; Nothing worked. Again when I changed $cmd to this :-- $cmd = "echo 'argv1 <- \"ex_1.R\"; source(argv1)' | " ."echo 'argv2 <-".$a."; source(argv1)' | " ."/usr/bin/R --vanilla --slave--args"; The r script could be invoked and bothe the arguments were available but with warnings:- WARNING: unknown option '--slave--args' R version 2.7.1 (2008-06-23) Copyright (C) 2008 The R Foundation for Statistical Computing ISBN 3-900051-07-0 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > argv2 <-1; source(argv1) *How should I pass multiple arguments from a php page to invoke a r scripts as well as make the arguments passed available to the r script?* Thanks Moumita [[alternative HTML version deleted]]