Question

I'm using a program called COLONY from some genetic analysis. Colony has an R package (rcolony).

What I need to do is move text files from a directory ("C:/GenSoftware/Colony/datFiles") into another directory ("C:/GenSoftware/Colony/") rename it "Colony2.dat", run colony, then when finished repeat the process for all files in the original directory.

This is what we've been able to come up with so far. The issue is that it seems to be trying to run every text file at the same time rather than cycling through them.

Any help would be much appreciated. Thanks in advance.

setwd("C:/GenSoftware/Colony/")
getwd()
datFiles <- list.files("datFiles")
library(rcolony)

for (dat in datFiles)
{
  setwd("C:/GenSoftware/Colony/datFiles")
  file.rename(dat,"Colony2.DAT")
  file.copy(from = "C:/GenSoftware/Colony/datFiles/Colony2.DAT",to = "C:/GenSoftware/Colony/")
  datPath <- "C:/GenSoftware/Colony/Colony2.DAT"
  setwd("C:/GenSoftware/Colony/")
  run.colony(colonyexecpath = "Colony2.exe", datPath, wait = FALSE, monitor = TRUE)
  setwd("C:/GenSoftware/Colony/datFiles/")
  file.rename("Colony2.DAT",dat)
}
Was it helpful?

Solution

setwd("C:/GenSoftware/Colony/datFiles")
listofFile = list.files()
Records <- as.data.frame(listofFile)
count <- nrow(Records)
x = 1:count

for(i in seq(along=x))
{
  file.rename(listofFile[i],"Colony2.DAT")
  file.copy(from = "C:/GenSoftware/Colony/datFiles/Colony2.DAT",to = "C:/GenSoftware/Colony/")
  datPath <- "C:/GenSoftware/Colony/Colony2.DAT"
  setwd("C:/GenSoftware/Colony/")
  run.colony(colonyexecpath = "Colony2.exe", datPath, wait = FALSE, monitor = TRUE)
  setwd("C:/GenSoftware/Colony/datFiles/")
  file.rename("Colony2.DAT",dat)
}

sorry didn't have time to test because I'm running some intensive stuff on my machine.

This will definitely show you it the process iterate through the directory of files

setwd("C:/GenSoftware/Colony/datFiles")
listofFile = list.files()
Records <- as.data.frame(listofFile)
count <- nrow(Records)
x = 1:count

for(i in seq(along=x))
{
  print(listofFile[i])
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top