Hey guys, Does anyone have an example of a REALLY simple shell script in R. Basically i want to run this command: library(MASS) wilcox.test(list1,list2,paired=TRUE,alternative=c("greater"),correct=TRUE,exact=FALSE) in a shell script something like this: #!/bin/bash R library(MASS) for i in *.out do wilcox.test($i,${i/out}.out2,paired=TRUE) >> $i.out done that i can run on a command line this this: sh R.sh because i've SO many files to run this command on. I've been googling, but i'm having trouble of just finding a simple example explaining how to make this shell script. Any help appreciated :) Aoife [[alternative HTML version deleted]]
You can do this in bash but why not just do it in R directly? You probably need list.files(pattern = ".out") to get started. Then just wrap your script in a function and pass it to (s|l)apply something like: sapply(list.files(pattern = *.out"), function(x) wilcox.test ( ... ) ) Michael On Wed, Apr 25, 2012 at 6:47 AM, aoife doherty <aoife.m.doherty at gmail.com> wrote:> Hey guys, > Does anyone have an example of a REALLY simple shell script in R. > > Basically i want to run this command: > > library(MASS) > wilcox.test(list1,list2,paired=TRUE,alternative=c("greater"),correct=TRUE,exact=FALSE) > > in a shell script something like this: > > #!/bin/bash > R > library(MASS) > for i in *.out > do > wilcox.test($i,${i/out}.out2,paired=TRUE) >> $i.out > done > > > that i can run on a command line this this: > sh R.sh > > > because i've SO many files to run this command on. > > > I've been googling, but i'm having trouble of just finding a simple example > explaining how to make this shell script. > > Any help appreciated :) > Aoife > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.
Check out the vignette for the optparse library: http://cran.r-project.org/web/packages/optparse/vignettes/optparse.pdf Super helpful library if you plan on making any semi-interesting command line scripts w/ R. -steve On Wed, Apr 25, 2012 at 6:47 AM, aoife doherty <aoife.m.doherty at gmail.com> wrote:> Hey guys, > Does anyone have an example of a REALLY simple shell script in R. > > Basically i want to run this command: > > library(MASS) > wilcox.test(list1,list2,paired=TRUE,alternative=c("greater"),correct=TRUE,exact=FALSE) > > in a shell script something like this: > > #!/bin/bash > R > library(MASS) > for i in *.out > do > wilcox.test($i,${i/out}.out2,paired=TRUE) >> $i.out > done > > > that i can run on a command line this this: > sh R.sh > > > because i've SO many files to run this command on. > > > I've been googling, but i'm having trouble of just finding a simple example > explaining how to make this shell script. > > Any help appreciated :) > Aoife > > ? ? ? ?[[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > 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.-- Steve Lianoglou Graduate Student: Computational Systems Biology ?| Memorial Sloan-Kettering Cancer Center ?| Weill Medical College of Cornell University Contact Info: http://cbio.mskcc.org/~lianos/contact