how to call .R script using .sh in windows

0

I have an analysis to run in skatMeta (R package). I received a runscript.sh that calls myfile.R to run the analysis. However, the script is written for Linux, but I only have Windows. I installed Cygwin, but now have no idea how to run it. The runscript.sh is:

for t in `echo A B` ; do 
  for i in `seq 1 22 ; echo X` ; 
  do 
       qth "export R_LIBS=~/lib/ ; 
       R --vanilla --args phenotype=$t chr=$i < ~/bin/skat.R" ;
  done ;
done

Can someone explain to me what should I do? I am all confused with what should I do: where these files should be located, is it OK if I have R and skatMeta installed for Windows,..I don't even know how to run it from cmd. And please, explain it as clear and simple as possible as I have no idea about these things (an explanation for dummies).

user284087

Posted 2013-12-23T13:44:59.730

Reputation: 1

Answers

0

First, lets look at what the script actually does:


The outer loop:

for t in `echo A B` ; do
(removed for clarity)      
done

This set the variable $t to A, executes the rest of the commands on the loop and then repeats it with $t set to B. It also does it in a weird way with executing a subshell to echo A and B. A simple for t in A B ; do would have done the same.


Next, the inner loop.

seq 1 22 ; echo X

seq creates a sequence of numbers from 1 to 22. Then X is added. You would write it in a longer form as for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 X


Finally, the commands:

Add this to the inner code and you get these commands:

 qth "export R_LIBS=~/lib/ ;  
 R --vanilla --args phenotype=A chr=1 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=A chr=2 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=A chr=3 < ~/bin/skat.R" ;  
 ...   
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=A chr=19 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=A chr=20 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=A chr=X < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;  
 R --vanilla --args phenotype=B chr=1 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=B chr=2 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=B chr=3 < ~/bin/skat.R" ;  
 ...   
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=B chr=19 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=B chr=20 < ~/bin/skat.R" ;  
 qth "export R_LIBS=~/lib/ ;   
 R --vanilla --args phenotype=B chr=X < ~/bin/skat.R" ;  


Now that we know what it does you can either run this by hand, write a batchfile or a powershell script. :-)

It would probably contain like something like this:

C:\program files\SkatMeta\R.exe --vanilla --args phenotype=A chr=1 < %%HOMEPATH%%\bin\skat.R" 
C:\program files\SkatMeta\R.exe --vanilla --args phenotype=A chr=2 < %%HOMEPATH%%\bin\skat.R"  
C:\program files\SkatMeta\R.exe --vanilla --args phenotype=A chr=3 < %%HOMEPATH%%\bin\skat.R" 

Etc etc with chr is 4 5 6 7 8 ... 21 22 X
And then the same for B

Where the first line it the full path to the R binary (default on windows is C:\program files\name_of_the_manufacturer\program_name.exe) and where the unix shortcut for home (~) has been replaced by %HOMEPATH%. The last probably expands to C:/users/your_username and I encapsulated it in double % signs which is needed for a batch file.

I will leave that part to an other poster, since windows scripting is very much not my forte.

Hennes

Posted 2013-12-23T13:44:59.730

Reputation: 60 739