Hi all, I am trying to get shell variable(s) into my R script in Linux . How do I get them? my shell script is t1.sh #!bin/bash Name=Alex; export Name Age=25; export Age How do get the Name and Age variables in my R script? My R script is test.R print " Your Name is $Name and you are $Age years old" My another shell script that call the R script is test.sh #!bin/bash source t1.sh Rscript test.R So by running this script ./test.sh I want get: Your Name is Alex and you are 25 years old I can define those variables in R but that is not my intention. Thank you in advance
?commandArgs -- Sent from my phone. Please excuse my brevity. On November 24, 2016 8:50:29 PM PST, Val <valkremk at gmail.com> wrote:>Hi all, > >I am trying to get shell variable(s) into my R script in Linux . How >do I get them? > >my shell script is >t1.sh > #!bin/bash > Name=Alex; export Name > Age=25; export Age > > >How do get the Name and Age variables in my R script? > >My R script is > >test.R >print " Your Name is $Name and you are $Age years old" > >My another shell script that call the R script is > >test.sh > #!bin/bash > source t1.sh > Rscript test.R >So by running this script ./test.sh > >I want get: Your Name is Alex and you are 25 years old > >I can define those variables in R but that is not my intention. > >Thank you in advance > >______________________________________________ >R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >https://stat.ethz.ch/mailman/listinfo/r-help >PLEASE do read the posting guide >http://www.R-project.org/posting-guide.html >and provide commented, minimal, self-contained, reproducible code.
> On Nov 24, 2016, at 8:50 PM, Val <valkremk at gmail.com> wrote: > > Hi all, > > I am trying to get shell variable(s) into my R script in Linux . How > do I get them? > > my shell script is > t1.sh > #!bin/bash > Name=Alex; export Name > Age=25; export Age > > > How do get the Name and Age variables in my R script? > > My R script is > > test.R > print " Your Name is $Name and you are $Age years old"You might want to look at `?system` and `?Sys.getenv`. Do note that for an R function the arguments need to be flanked by parentheses.> > My another shell script that call the R script is > > test.sh > #!bin/bash > source t1.sh > Rscript test.R > So by running this script ./test.sh > > I want get: Your Name is Alex and you are 25 years old > > I can define those variables in R but that is not my intention.David Winsemius Alameda, CA, USA