Command Plink in R (for loop)
1
0
Entering edit mode
8.9 years ago
hessjl ▴ 90

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

R • 4.0k views
ADD COMMENT
1
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
6
Entering edit mode
8.9 years ago
PoGibas 5.1k

This should work.

library(foreach)
foreach(i=input_names) %do% {
    cmd <- paste0("./plink --noweb --bfile ", i, " --freq --out  test_", i)
    system(cmd)
}
ADD COMMENT
1
Entering edit mode

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

ADD REPLY

Login before adding your answer.

Traffic: 1554 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6