0

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)
}
3
  • What you have written looks fine. It definitely isn't trying to run them at the same time. Can you post some more information about what is happening when you run it? Commented Aug 29, 2013 at 22:27
  • Yes, you appear to be correct. It is running three instances of colony though. I'm not sure if the instances are analyzing the same file three times or if it is somehow parsing it out. I just acquired a couple more computer to run things on and there may have been some version incompatibility occurring because it now seems to be running just one instance. Here is a screenshot of what was occurring last night when it was running two instances: i.imgur.com/u3BnMQ7.png Thanks taking the time to help me. Commented Aug 30, 2013 at 19:46
  • This is the current state of things i.imgur.com/GT3OPhU.png Commented Aug 30, 2013 at 20:00

1 Answer 1

1
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])
}
Sign up to request clarification or add additional context in comments.

7 Comments

Is it posible to use the same code to read a file with the same name but allocated in a different folders in a directory? I don't know how to make that in R because in others software is to slow!
Do you mean search for file name in different directories?
example: We want to process file TotalSodaSales.txt and the file is the following directories: c:\sodasales\2011, c:\sodasales\2012, c:\sodasales\2013, c:\sodasales\2014
Yes, Exactly you said but in my case I have excel files but I am in trouble with that reading of files!
Please If you know how to read the same file from different directories I would thank you @user2600629
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.