Question: Command Plink in R (for loop)
0
gravatar for hessjl
2.5 years ago by
hessjl40
United States
hessjl40 wrote:

I'll first layout the block of R code that I'm working on:

for( i in 1:length(input_names)){
  input_names[[i]] -> MYDATA
  system("./plink --noweb --bfile MYDATA --freq --out test[[i]]")
}

This will return an error as there is no file named "MYDATA" in the working directory. The point is that I want the system command plink to recognize MYDATA as a R object, retrieve the filename whose string matches that of MYDATA, and  perform the function --freq and write the results to file name test (test1,test2,test3...etc.,). 

Is there any way to use system( ) in a for loop on special R objects? If so, please explain how that is done. 

Puzzled and thankful,

Jon

for loop R • 1.0k views
ADD COMMENTlink modified 2.5 years ago by PoGibas4.7k • written 2.5 years ago by hessjl40
1

Any reason for not using a bash script or even Python? R seems an odd choice for this particular task.

ADD REPLYlink written 2.5 years ago by h.mon9.6k

As general interest to know if R can do this, since it's my go-to language. 

ADD REPLYlink written 2.5 years ago by hessjl40
5
gravatar for PoGibas
2.5 years ago by
PoGibas4.7k
Vilnius
PoGibas4.7k wrote:

This should work.

library(foreach)
foreach(i=input_names) %do% {
    cmd <- paste0("./plink --noweb --bfile ", i, " --freq --out  test_", i)
    system(cmd)
}
ADD COMMENTlink modified 2.5 years ago • written 2.5 years ago by PoGibas4.7k
1

You can run foreach commands in parallel (many plinks at once). 

ADD REPLYlink written 2.5 years ago by PoGibas4.7k
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1023 users visited in the last hour