This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Command Plink in R (for loop)

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

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

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

1 answer

This should work.

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

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

Log in to answer this question.