Re: [R] R shell script

2012-04-25 Thread Steve Lianoglou
Hi,

On Wed, Apr 25, 2012 at 11:11 AM, aoife doherty
 wrote:
> Thanks for replying.
>
> My problem is that i have say 50 input files, that i wanted to run a
> particular command on, get 50 output files, and then when i close R, have
> them in my directory?
>
> so for example if i say:
>
>>R
>
>>library(MASS)
>
>>list.files(pattern = ".out")
>
>>sapply(list.files(pattern  = *.out"), function(x) wilcox.test ( ... ) )
>
> << when i close R the outputs are still there>>>
>
> i thought this might be easier in a shell way?

In this case, just make your function write a text file -- you have to
figure out what you want to save and serialize it to text. Or you can
write as many output rds (or rda) files as you do tests, for instance:

filez <- list.files(pattern="*.out")
for (f in filez) {
  ## something to load the data in file `f` I presume
  w <- wilcox.test(... on the data you loaded ...)

  saveRDS(w, gsub('.out', '.rds', f) ## if you want to save the object
}

or
info <- lapply(filez, function(x) {
  ## load the file
  w <- wilcox.test(... on the data you loaded ...)
  data.frame(file.name=x, statistic=w$statistic, p.value=w$p.value,
... anything else you want?)
})
result <- do.call(rbind, info)
write.table(result, 'wilcox.results.txt', ...)

HTH,
-steve

>
>
>
> On Wed, Apr 25, 2012 at 4:03 PM, R. Michael Weylandt <
> michael.weyla...@gmail.com> wrote:
>
>> 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
>>  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@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.
>>
>
>        [[alternative HTML version deleted]]
>
> __
> R-help@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

__
R-help@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.


Re: [R] R shell script

2012-04-25 Thread mlell08
On 25.04.2012 17:12, Steve Lianoglou wrote:
> 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
>  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@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.
>
>
Hi Aoife
you can use the capture.output function if you want so sent R output to
a file

Regards!

-- 
GnuPG Key:7340821E



[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] R shell script

2012-04-25 Thread Steve Lianoglou
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
 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@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

__
R-help@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.


Re: [R] R shell script

2012-04-25 Thread aoife doherty
Thanks for replying.

My problem is that i have say 50 input files, that i wanted to run a
particular command on, get 50 output files, and then when i close R, have
them in my directory?

so for example if i say:

>R

>library(MASS)

>list.files(pattern = ".out")

>sapply(list.files(pattern  = *.out"), function(x) wilcox.test ( ... ) )

<<>>

i thought this might be easier in a shell way?



On Wed, Apr 25, 2012 at 4:03 PM, R. Michael Weylandt <
michael.weyla...@gmail.com> wrote:

> 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
>  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@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.
>

[[alternative HTML version deleted]]

__
R-help@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.


Re: [R] R shell script

2012-04-25 Thread R. Michael Weylandt
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
 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@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.

__
R-help@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.


[R] R shell script

2012-04-25 Thread aoife doherty
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@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.