[Sciviews-commits] r308 - in pkg/svMisc: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Sep 14 10:00:37 CEST 2010


Author: phgrosjean
Date: 2010-09-14 10:00:37 +0200 (Tue, 14 Sep 2010)
New Revision: 308

Modified:
   pkg/svMisc/R/captureAll.R
   pkg/svMisc/man/captureAll.Rd
Log:
Further bugs correction in captureAll()

Modified: pkg/svMisc/R/captureAll.R
===================================================================
--- pkg/svMisc/R/captureAll.R	2010-09-11 10:48:19 UTC (rev 307)
+++ pkg/svMisc/R/captureAll.R	2010-09-14 08:00:37 UTC (rev 308)
@@ -1,4 +1,4 @@
-captureAll <- function (expr, split = FALSE)
+captureAll <- function (expr, split = FALSE, file = NULL)
 {
 	## If expr is NA, just return it
 	if (!is.language(expr))
@@ -8,9 +8,10 @@
 	split <- isTRUE(split)
 
 	## captureAll() is inspired from capture.output(), but it captures
-	## both the output and the message streams
+	## both the output and the message streams (without redirecting
+	## the message stream, but by using a withCallingHandlers() construct).
 	rval <- NULL	# Just to avoid a note during code analysis
-	file <- textConnection("rval", "w", local = TRUE)
+	if (is.null(file)) file <- textConnection("rval", "w", local = TRUE)
 	sink(file, type = "output", split = split)
 
 	## This is a hack to display warning(..., immediate.) correctly
@@ -36,7 +37,7 @@
 	on.exit({
 		sink(type = "output")
 		close(file)
-		if (exists("warning", envir = TempEnv()))
+		if (exists("warning", envir = TempEnv(), inherits = FALSE))
 			rm("warning", envir = TempEnv())
 	})
 
@@ -69,8 +70,9 @@
 				## Result depends upon 'warn'
 				Warn <- getOption("warn")
 
-				## If warning generated in eval environment,  make it NULL
-				try(if (!is.null(call) && identical(call[[1L]], quote(eval)))
+				## If warning generated in eval environment, make it NULL
+				try(if (!is.null(call)  && !is.symbol(call) &&
+					identical(call[[1L]], quote(eval)))
 					e$call <- NULL, silent = TRUE)
 
 				if (Warn < 0) { # Do nothing!
@@ -121,7 +123,8 @@
 				## try(stop(...)).  This will need adjusting if the
 				## implementation of tryCatch changes.
 				## Use identical() since call[[1]] can be non-atomic.
-				try(if (!is.null(call) && identical(call[[1L]], quote(eval)))
+				try(if (!is.null(call) && !is.symbol(call) &&
+					identical(call[[1L]], quote(eval)))
 					call <- NULL, silent = TRUE)
 				if (!is.null(call)) {
 					dcall <- deparse(call)[1L]

Modified: pkg/svMisc/man/captureAll.Rd
===================================================================
--- pkg/svMisc/man/captureAll.Rd	2010-09-11 10:48:19 UTC (rev 307)
+++ pkg/svMisc/man/captureAll.Rd	2010-09-14 08:00:37 UTC (rev 308)
@@ -13,14 +13,18 @@
 }
 
 \usage{
-captureAll(expr, split = FALSE)
+captureAll(expr, split = FALSE, file = NULL)
 }
 
 \arguments{
   \item{expr}{ a valid R expression to evaluate (names and calls are also
     accepted). }
   \item{split}{ do we split output, that is, do we also issue it at the R console
-  too, or do we only capture it silently? }
+    too, or do we only capture it silently? }
+  \item{file}{ a file, or a valid opened connection where output is sinked. It
+    is closed at the end, and the function returns \code{NULL} in this case. If
+	\code{file = NULL} (by default), a textConnection() captures the output and
+	it is returned is a character string by the function. }
 }
 
 \value{



More information about the Sciviews-commits mailing list