[rkward-cvs] SF.net SVN: rkward:[3157] branches/2010_10_18_backend_restructuring_branch/ rkward/rbackend/rpackages/rkward/R/internal.R

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Oct 27 13:37:51 UTC 2010


Revision: 3157
          http://rkward.svn.sourceforge.net/rkward/?rev=3157&view=rev
Author:   tfry
Date:     2010-10-27 13:37:50 +0000 (Wed, 27 Oct 2010)

Log Message:
-----------
Fix the plugin message capturing.

Modified Paths:
--------------
    branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rpackages/rkward/R/internal.R

Modified: branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rpackages/rkward/R/internal.R	2010-10-27 13:04:14 UTC (rev 3156)
+++ branches/2010_10_18_backend_restructuring_branch/rkward/rbackend/rpackages/rkward/R/internal.R	2010-10-27 13:37:50 UTC (rev 3157)
@@ -335,19 +335,23 @@
 
 # for caputring message output while running a plugin command
 ".rk.capture.messages" <- function () {
-	if (exists (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)) {
+	if (exists (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)) {
 		# We don't support nesting, so purge it, first
 		.rk.print.captured.messages ()
 	}
+	if (!exists (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)) {
+		sinkfile <- tempfile ("rkward_plugin_messages")
+		assign (".rk.capture.messages.sinkfile", sinkfile, envir=as.environment ("package:rkward"))
+	} else {
+		sinkfile <- get (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)
+	}
 
-	sinkfile <- tempfile ()
-	assign (".rk.capture.messages.sinkfile", sinkfile, envir=as.environment ("package:rkward"))
 	sink (file (sinkfile, open="w"), type="message")
 	assign (".rk.capture.messages.sinknumber", sink.number ("message"), envir=as.environment ("package:rkward"))
 }
 
-".rk.print.captured.messages" <- function (clear=TRUE) {
-	if (!exists (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)) return ()
+".rk.print.captured.messages" <- function () {
+	if (!exists (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)) return ()
 
 	sinkfile <- get (".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"), inherits=FALSE)
 	if (file.exists (sinkfile)) {
@@ -358,20 +362,17 @@
 		}
 	}
 
-	if (clear) {
-		sinknumber <- get (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)
-		if (sink.number (type="message") > sinknumber) {
-			stop ("Another message sink appears to be in place. Remove that, first")
-		} else if (sink.number (type="message") < sinknumber) {
-			warning ("Message sink has been removed, already.")
-		} else {
-			sink (type="message")	# remove it
-			con <- getConnection (sinknumber)
-			con.close ()
-		}
-		if (file.exists (sinkfile)) file.remove (sinkfile)
-		remove (list=".rk.capture.messages.sinkfile", envir=as.environment ("package:rkward"))
+	sinknumber <- get (".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"), inherits=FALSE)
+	if (sink.number (type="message") == sinknumber) {
+		sink (type="message")	# remove it
+	} else {
+		warning ("Message sink has been added or removed since last call to .rk.capture.messages().")
 	}
+
+	con <- getConnection (sinknumber)
+	close (con)
+
+	remove (list=".rk.capture.messages.sinknumber", envir=as.environment ("package:rkward"))
 }
 
 # Start recording commands that are submitted from rkward to R.


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the rkward-tracker mailing list