[Rodbcext-commits] r53 - pkg/genutils/R

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Apr 11 10:21:00 CEST 2014


Author: jaunario
Date: 2014-04-11 10:20:59 +0200 (Fri, 11 Apr 2014)
New Revision: 53

Modified:
   pkg/genutils/R/worker.r
Log:
in get.jobs, used function match instead of grep.

Modified: pkg/genutils/R/worker.r
===================================================================
--- pkg/genutils/R/worker.r	2014-03-27 06:23:25 UTC (rev 52)
+++ pkg/genutils/R/worker.r	2014-04-11 08:20:59 UTC (rev 53)
@@ -7,27 +7,33 @@
 	myjob <- vector()
 	worker.id <- Sys.getpid()
 	
-	if(!file.exists(jobfile)){
-		jobs <- initjobs
-		save(jobs, file=jobfile)
-		
-		filelock <- data.frame(filename=character(0),worker=numeric(0))
-		filelock[1,] <- NA
-		filelock$filename[1] <- jobfile   
-		write.csv(filelock,"files.csv",row.names=FALSE)		
- 
+	if(!file.exists("files.csv")){
+		filelock <- data.frame(filename=character(0),worker=numeric(0), stringsAsFactors=FALSE)		
+	} else {
+		filelock <- read.csv("files.csv",stringsAsFactors=FALSE)
 	}
 	
+	if(is.na(match(jobfile,filelock$filename))){
+		jobs <- initjobs
+		save(jobs, file=jobfile)		
+		new.id <- nrow(filelock)+1
+		filelock[new.id,] <- NA		
+		filelock$filename[new.id] <- jobfile   
+		write.csv(filelock,"files.csv",row.names=FALSE)		 
+	} 
+	
 	tries <- 0
 	repeat{
 		filelock <- read.csv("files.csv",stringsAsFactors=FALSE)
-		if(is.na(filelock$worker[filelock$filename==jobfile])){
-			filelock$worker[filelock$filename==jobfile] <- worker.id
+		if(is.na(filelock$worker[match(jobfile,filelock$filename)])){
+			filelock$worker[match(jobfile,filelock$filename)] <- worker.id
 			write.csv(filelock,"files.csv",row.names=FALSE)
 			load(jobfile)
-			myjob <- jobs[1:min(workload,length(jobs))] 
-			jobs <- jobs[!jobs %in% myjob]
-			save(jobs, file=jobfile)
+			if(length(jobs)>0){
+				myjob <- jobs[1:min(workload,length(jobs))] 
+				jobs <- jobs[!jobs %in% myjob]
+				save(jobs, file=jobfile)				
+			}
 			filelock$worker[filelock$filename==jobfile] <- NA
 			write.csv(filelock,"files.csv",row.names=FALSE)
 			break
@@ -42,3 +48,19 @@
 	}
 	return(myjob)
 }
+
+combine.output <- function(newdata, out.rdata="output.Rdata",delay=10){
+	success <- FALSE
+	
+	if(!file.exists("files.csv")){
+		filelock <- data.frame(filename=character(0),worker=numeric(0), stringsAsFactors=FALSE)		
+	} else {
+		filelock <- read.csv("files.csv",stringsAsFactors=FALSE)
+	}
+	
+	if(!file.exists(out.rdata)){
+		filelock <- read.csv("files.csv",stringsAsFactors=FALSE)		
+	}
+	success <- TRUE
+	return(success)	
+}



More information about the Rodbcext-commits mailing list