[Rcolony-commits] r18 - in pkg: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Apr 23 16:24:08 CEST 2009


Author: jonesor
Date: 2009-04-23 16:24:08 +0200 (Thu, 23 Apr 2009)
New Revision: 18

Added:
   pkg/man/build.colony.input.Rd
Modified:
   pkg/R/get.interm.data.R
   pkg/R/monitor.colony.R
   pkg/R/run.colony.R
Log:
Added the build.colony.input.Rd file.

Modified: pkg/R/get.interm.data.R
===================================================================
--- pkg/R/get.interm.data.R	2009-04-23 14:17:22 UTC (rev 17)
+++ pkg/R/get.interm.data.R	2009-04-23 14:24:08 UTC (rev 18)
@@ -1,11 +1,13 @@
-get.interm.data<-function(v1="CrLogL",datadir){
+get.interm.data<-function(variable="CrLogL",datadir=getwd(),n=1){
 
-getval<-function(v1,xx){
+getval<-function(variable,xx){
 
-ind<-grep(paste(v1,"=",sep=""),xx)
-s1<-"[A-Za-z =0-9,]*"
-s2<-"[ ]*([-.+E0-9]+),[A-Z#a-z =0-9,]*"
-s3<-paste(s1,paste(v1,"=",sep=""),s2,sep="")
+ind<-grep(paste(variable,"=",sep=""),xx)
+
+
+s1<-"[A-Za-z =0-9,.#+-]*"
+s2<-"[ ]*([-.+E0-9]+)[%A-Z#a-z =0-9,.]*"
+s3<-paste(s1,paste(variable,"=",sep=""),s2,sep="")
 x.out<-NULL
 
 for (i in 1:length(ind)){
@@ -17,10 +19,24 @@
 outfile<-readLines(paste(datadir,"temp.txt",sep=""))
 
 Itr<-getval("Itr",outfile)
-CrLogL<-getval(v1,outfile)
-chk<-c(length(Itr),length(CrLogL))
+length(Itr)
 
-df1<-data.frame(Itr=Itr[1:min(chk)],CrLogL=CrLogL[1:min(chk)])
+assign(variable,getval(variable,outfile))
+
+if(length(get(variable))==2*length(Itr)){
+assign(variable,get(variable)[rep(1:2,length.out=length(get(variable)))==n])
+
+chk<-c(length(Itr),length(get(variable)))
+df1<-data.frame(Itr=Itr[1:min(chk)],XX=get(variable)[1:min(chk)])
+
+}else{
+	chk<-c(length(Itr),length(get(variable)))
+	df1<-data.frame(Itr=Itr[1:min(chk)],XX=get(variable)[1:min(chk)])}
+
+names(df1)[2]<-variable
+
 return(df1)
+
 }
 
+

Modified: pkg/R/monitor.colony.R
===================================================================
--- pkg/R/monitor.colony.R	2009-04-23 14:17:22 UTC (rev 17)
+++ pkg/R/monitor.colony.R	2009-04-23 14:24:08 UTC (rev 18)
@@ -1,9 +1,7 @@
 
-monitor.colony<-function(datadir,interv.t=3,last.few=10){
+monitor.colony<-function(datadir=getwd(),variable="CrLogL",interv.t=2,last.few=10,n=1,showres=FALSE){
 
- # if(length(list.files(datadir,pattern=".Ne"))>0){stop("There are already files present in output directory. Remove them and start again.")}
 
-
 MidResult<-NULL
 
   #Get start time
@@ -11,18 +9,18 @@
   
   elapsed.t<-0
   
-  #while(length(list.files(datadir,pattern=".Ne"))<1){#run forever
-  while(TRUE){#run forever
+  hell<-"warm"
+  while(hell=="warm"){#run forever
   
   t2<-Sys.time()
   elapsed.t<-as.numeric(t2-t1)
   
   if(elapsed.t>interv.t){
   
-  fileok<-file.exists("temp.txt")
+  fileok<-file.exists(paste(datadir,"temp.txt",sep=""))
   
-if(fileok==TRUE&!is.na(get.interm.data(datadir=datadir)[1,1])){
-	MidResult2<-get.interm.data(datadir=datadir)
+if(fileok==TRUE&!is.na(get.interm.data(datadir=datadir,variable=variable,n=n)[1,1])){
+	MidResult2<-get.interm.data(datadir=datadir,variable=variable,n=n)
 	MidResult<-rbind(MidResult,MidResult2)
 	MidResult<-unique(MidResult)
 
@@ -30,7 +28,7 @@
 y<-MidResult[,2]
   
 plot(x,y,type="b",xlab="",ylab="")
-title(xlab="NumIterate",ylab="CrLogL")
+title(xlab="NumIterate",ylab=variable)
 
 #add routine to delete contents if file is too big.
 #50lines?
@@ -41,9 +39,11 @@
 to<-length(tmp)
 
 write.table(tmp[from:to],file="temp.txt",row.names=FALSE,col.names=FALSE,quote=FALSE)
-print(MidResult)
-cat("\n")
 
+if(showres==TRUE){print(MidResult)}
+
+cat("Plotting. Hit Esc to stop\n")
+
 	}else{cat("Waiting...\n")}
   
   
@@ -53,7 +53,8 @@
   
   
   }
-  }}
+  }
+  }
 
 
 

Modified: pkg/R/run.colony.R
===================================================================
--- pkg/R/run.colony.R	2009-04-23 14:17:22 UTC (rev 17)
+++ pkg/R/run.colony.R	2009-04-23 14:24:08 UTC (rev 18)
@@ -1,7 +1,6 @@
-`run.colony` <-
-function(colonyexec="Colony2.exe",colonypath="/Users/ZSL/Documents/IoZ/Colony/",datadir="/Users/ZSL/Desktop/Test/",filename="Test1.DAT",wait=TRUE,monitor=TRUE){
+run.colony<-function(colonyexec="Colony2.exe",colonypath,datadir,filename,wait=TRUE,monitor=TRUE){
 	 #don't forget the trailing slash!
-	 
+
 	 cat("Be aware: this may take several minutes, hours, or even weeks to run, depending on the settings.\n")
 	 
 	 current.wd<-getwd()
@@ -13,23 +12,40 @@
 	 outputfilename <- sub("[\t\n\f\r ]*$", "", outputfilename); #remove trailing whitespace
 	 outputfilename
 	 
+	 	 if(file.exists(paste(datadir,outputfilename,".MidResult",sep=""))){stop("\nThere are output files already in the directory. \nColony has already run. \nTry deleting (or moving) these files and starting again.\n")}
+
+	 
 	 setwd(datadir)
 	 
 	 platform<-.Platform
+if(monitor==TRUE&wait==TRUE){stop("If you want to monitor the output, you must set wait as FALSE. Otherwise you cannot run other functions in the same R console.")}
 	 
 	 if(platform$OS.type=="unix"){
-	 #Unix/MacOSX commands
-	 
+
+#Unix/MacOSX commands
+	
+#Copy Colony2 program to the working directory
 	system(paste("cp",paste(colonypath,colonyexec,sep=""),datadir,sep=" "))
+	
+#Rename the DAT file as Colony2.DAT
 	system(paste("mv",paste(datadir,filename,sep=""),paste(datadir,"Colony2.DAT",sep=""),sep=" "))
-
+	
+#Make a copy of the DAT file in it's original name
+	system(paste("cp",paste(datadir,"Colony2.DAT",sep=""),paste(datadir,filename,sep=""),sep=" "))
+	
+#Run Colony
+#If monitor = TRUE, then a temp.txt file is produced (temp.txt). This can be monitored using monitor.colony.R so progress can be observed.
+#wait should be set to FALSE if monitor =TRUE
+#It is recommended that monitor = TRUE only be used if you will periodically monitor the system, otherwise the text file will grow very large and may burden the system.
+#There is currently no way of monitoring the Windows system.
 if(monitor==TRUE){system("./Colony2.exe 2>&1 | tee temp.txt",wait=wait)}else{system("./Colony2.exe",wait=wait)}
 
-	system(paste("mv",paste(datadir,"Colony2.DAT",sep=""),paste(datadir,filename,sep=""),sep=" "))
-	system("rm Colony2.exe")
+#Remove the Colony2.exe and 
+	system(paste("rm",colonyexec))
+	system("rm Colony2.DAT")
 
-#Check whether Colony has finished, if it has delete this "temp.txt" file.
-#system("rm temp.txt",ignore.stderr=TRUE)
+
+
 }else{if(platform$OS.type=="windows"){
 	#Windows commands
 	shell(paste("copy",paste(colonypath,colonyexec,sep=""),datadir,sep=" "))#Copy the colony exe file to the project directory	

Added: pkg/man/build.colony.input.Rd
===================================================================
--- pkg/man/build.colony.input.Rd	                        (rev 0)
+++ pkg/man/build.colony.input.Rd	2009-04-23 14:24:08 UTC (rev 18)
@@ -0,0 +1,38 @@
+\name{build.colony.input}
+\alias{build.colony.input}
+
+\title{A wizard-like function to help build Colony2 input files.}
+
+\description{
+This function prompts the user to provide information about their system in order to correctly build and format a Colony2 input file.
+}
+
+\usage{
+build.colony.input(wd=getwd(),name="Colony2.DAT")
+
+}
+
+\arguments{
+  \item{wd}{The directory where the generated file will be placed. The default is the current working directory.}
+  \item{name}{The desired filename for the Colony input file (the default is Colony2.DAT).}
+ }
+
+\details{
+  
+}
+
+\value{
+A text file is produced.
+}
+
+\references{}
+\author{Owen R. Jones}
+\note{}
+\seealso{\code{\link{run.colony}}}
+\examples{
+
+}
+
+% Add one or more standard keywords, see file 'KEYWORDS' in the
+% R documentation directory.
+\keyword{ manip }



More information about the Rcolony-commits mailing list