[rkward-cvs] SF.net SVN: rkward:[3708] trunk/rkward

tfry at users.sourceforge.net tfry at users.sourceforge.net
Wed Aug 3 08:42:56 UTC 2011


Revision: 3708
          http://rkward.svn.sourceforge.net/rkward/?rev=3708&view=rev
Author:   tfry
Date:     2011-08-03 08:42:56 +0000 (Wed, 03 Aug 2011)

Log Message:
-----------
R 2.14.x appears to lock all bindings in the rkward environment. Work around that.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.replace.function.Rd
    trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.show.messages.Rd
    trunk/rkward/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/ChangeLog	2011-08-03 08:42:56 UTC (rev 3708)
@@ -1,3 +1,4 @@
+- Add support R 2.14.x
 - Removed option to set options("printcmd")
 - New option to run arbitrary (setup) commands in each session
 - Added new pseudo graphics device "rk.printer.device" to provide printing via the KDE printer dialog

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal.R	2011-08-03 08:42:56 UTC (rev 3708)
@@ -63,13 +63,12 @@
 	}
 }
 
-".rk.rkreply" <- NULL
-".rk.set.reply" <- function (x) .rk.rkreply <<- x
+".rk.set.reply" <- function (x) .rk.variables$.rk.rkreply <- x
 
 ".rk.do.call" <- function (x, args=NULL) {
 	.rk.set.reply (NULL)
 	.Call ("rk.do.command", c (x, args));
-	return (.rk.rkreply)
+	return (.rk.variables$.rk.rkreply)
 }
 
 ".rk.do.plain.call" <- function (x, args=NULL, synchronous=TRUE) {
@@ -290,8 +289,6 @@
 	ret
 }
 
-".rk.output.html.file" <- NULL
-
 "Sys.setlocale" <- function (category = "LC_ALL", locale = "", ...) {
 	if (category == "LC_ALL" || category == "LC_CTYPE" || category == "LANG") {
 		allow <- .rk.do.plain.call ("preLocaleChange", NULL)
@@ -344,19 +341,24 @@
 	}
 }
 
+# General purpose storage environment (which will hopefully never get locked by R)
+".rk.variables" <- new.env ()
+.rk.variables$.rk.active.device <- 1
+.rk.variables$.rk.output.html.file <- NULL
+.rk.variables$.rk.rkreply <- NULL
+
+".rk.backups" <- new.env ()
 # Tries to replace a function inside its environemnt/namespace.
 # Function formals are copied from the original.
-# A backup of the original is stored as rkward::.rk.FUNCTIONNAME.default
+# A backup of the original is stored as rkward::.rk.backups$FUNCTIONNAME
 "rk.replace.function" <- function (functionname, environment, replacement, copy.formals=TRUE) {
 	original <- get (functionname, envir=environment, inherits=FALSE)
 
 	# create a backup
-	backupname <- paste (".rk.", functionname, ".default", sep="")
-	assign (backupname, original, envir=as.environment ("package:rkward"))
+	assign (functionname, original, envir=.rk.backups)
 
 	if (copy.formals) formals (replacement) <- formals (original)
 	environment (replacement) <- environment (original)
-	assign (functionname, replacement, envir=as.environment ("package:rkward"))
 	try (
 		if (bindingIsLocked (functionname, environment)) {
 			unlockBinding (functionname, environment)
@@ -411,7 +413,7 @@
 			}
 
 			# for text list, use the default implementation
-			eval (body (rkward::.rk.select.list.default))
+			eval (body (.rk.backups$select.list))
 		})
 
 	rk.replace.function ("menu", as.environment ("package:utils"),
@@ -422,11 +424,10 @@
 			}
 
 			# for text menus, use the default implementation
-			eval (body (.rk.menu.default))
+			eval (body (.rk.backups$menu))
 		})
 
 	# call separate assignments functions:
 	if (exists (".rk.fix.assignments.graphics")) eval (body (.rk.fix.assignments.graphics)) # internal_graphics.R
 }
 
-.rk.active.device <- 1

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2011-08-03 08:42:56 UTC (rev 3708)
@@ -79,7 +79,7 @@
 	rk.replace.function ("plot.new", as.environment ("package:graphics"),
 		function () {
 			rk.record.plot$.plot.new.hook ()
-			eval (body (.rk.plot.new.default))
+			eval (body (.rk.backups$plot.new))
 		})
 
 	rk.replace.function ("dev.off", as.environment ("package:grDevices"),
@@ -90,7 +90,7 @@
 			# see http://thread.gmane.org/gmane.comp.statistics.rkward.devel/802
 			.rk.do.call ("killDevice", as.character (which))
 			
-			ret <- eval (body (.rk.dev.off.default))
+			ret <- eval (body (.rk.backups$dev.off))
 
 			printfile <- .rk.printer.devices[[as.character (which)]]
 			if (!is.null (printfile)) {
@@ -103,7 +103,7 @@
 
 	rk.replace.function ("dev.set", as.environment ("package:grDevices"),
 		function () {
-			ret <- eval (body (.rk.dev.set.default))
+			ret <- eval (body (.rk.backups$dev.set))
 			
 			if (getOption ("rk.enable.graphics.history") && rk.record.plot$.is.device.managed (which))
 				rk.record.plot$.set.trellis.last.object (which)
@@ -135,7 +135,7 @@
 				function () {
 					## TODO: add specific support for ggplots?
 					rk.record.plot$.plot.new.hook ()
-					ret <- eval (body (.rk.grid.newpage.default))
+					ret <- eval (body (.rk.backups$grid.newpage))
 				})
 	)
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public.R	2011-08-03 08:42:56 UTC (rev 3708)
@@ -124,12 +124,12 @@
 }
 
 "rk.get.output.html.file" <- function () {
-	return (.rk.output.html.file)
+	return (.rk.variables$.rk.output.html.file)
 }
 
 "rk.set.output.html.file" <- function (x) {
 	stopifnot (is.character (x))
-	assign (".rk.output.html.file", x, as.environment ("package:rkward"))
+	assign (".rk.output.html.file", x, .rk.variables)
 
 	if (!file.exists (x)) {
 		.rk.cat.output (paste ("<?xml version=\"1.0\" encoding=\"", .Call ("rk.locale.name"), "\"?>\n", sep=""))

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2011-08-03 08:42:56 UTC (rev 3708)
@@ -8,7 +8,7 @@
 	if (!is.numeric (height)) height <- 480
 	if (is.null (device.type)) device.type <- "PNG"	# default behavior is PNG for now
 
-	assign (".rk.active.device", dev.cur (), pos = "package:rkward")
+	assign (".rk.active.device", dev.cur (), .rk.variables)
 
 	ret <- NULL
 	if (device.type == "PNG") {
@@ -50,7 +50,7 @@
 	
 	# dev.off () sets dev.next () as active, which may not have been active before rk.graph.on was called;
 	# so reset the correct device as active:
-	i <- get (".rk.active.device", pos = "package:rkward")
+	i <- get (".rk.active.device", .rk.variables)
 	if ((!is.null (i)) && (i %in% dev.list ())) ret <- dev.set (i)
 	ret
 }
@@ -180,14 +180,14 @@
 		d.cur <- dev.cur ()
 		histPositions <<- list ("1" = .hP.template)
 		for (d in as.character (.osd)) {
-			.rk.dev.set.default (as.numeric (d))
+			.rk.backups$dev.set (as.numeric (d))
 			if (is.null (recordPlot ()[[1]])) # empty device
 				histPositions [[d]] <<- .hP.template
 			else
 				histPositions [[d]] <<- modifyList(.hP.template, 
 					list (is.this.plot.new = TRUE, is.this.dev.new = FALSE, pkg = "unknown"))
 		}
-		.rk.dev.set.default (d.cur)
+		.rk.backups$dev.set (d.cur)
 		.set.hP.names ()
 	}
 	onDelDevice <- function (devId = dev.cur())
@@ -324,9 +324,9 @@
 		unsplot <- NULL
 		unsplot.ls <- NULL
 		if (pkg %in% c("graphics", "unknown")) {
-			.rk.dev.set.default (as.numeric (devId))
+			.rk.backups$dev.set (as.numeric (devId))
 			try (unsplot <- recordPlot(), silent=TRUE)
-			.rk.dev.set.default (devId.cur)
+			.rk.backups$dev.set (devId.cur)
 		} else if  (pkg == "lattice") {
 			unsplot <- histPositions [[devId]]$plot
 			unsplot.ls <- histPositions [[devId]]$tlo.ls
@@ -511,7 +511,7 @@
 		
 		devId <- as.character (devId)
 		cur.devId <- dev.cur ()
-		.rk.dev.set.default (as.numeric(devId))
+		.rk.backups$dev.set (as.numeric(devId))
 		
 		st <- .sP.index [[n]]
 		pkg <- savedPlots [[st]]$pkg
@@ -532,7 +532,7 @@
 		histPositions [[devId]] <<- modifyList (.hP.template, 
 			list (is.this.plot.new = FALSE, is.this.dev.new = FALSE, pos.prev = n, pos.cur = n, pkg = pkg, 
 				call = savedPlots [[st]]$call, plot = savedPlots [[st]]$plot, tlo.ls = savedPlots [[st]]$tlo.ls))
-		.rk.dev.set.default (cur.devId)
+		.rk.backups$dev.set (cur.devId)
 		invisible()
 	}
 	

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.replace.function.Rd
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.replace.function.Rd	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.replace.function.Rd	2011-08-03 08:42:56 UTC (rev 3708)
@@ -17,7 +17,7 @@
 \details{
   \code{rk.replace.function} can be used to replace a function inside a different package / namespace. It is mainly intended for internal usage inside rkward, e.g. to replace \code{menu} and \code{select.list} with appropriate GUI implementations.
 
-  The original function is assigned to the environment of the rkward package, as ".rk.FUNCTIONAME.default", and can be referred to from the replacement. WARNING: This mechansim does not support several subsequent replacments of the same function.
+  The original function is assigned to the environment \code{rkward::.rk.backups} with the same name as the original, and can be referred to from the replacement. WARNING: This mechansim does not support several subsequent replacments of the same function.
 
   WARNING: This function can be used to alter - and disrupt - internal functions in arbitrary ways. You better know what you are doing.
 
@@ -39,7 +39,7 @@
 rk.replace.function ("history", as.environment ("package:utils"),
   function () {
     cat ("This is what you typed:\n")
-    eval (body (.rk.history.default))
+    eval (body (.rk.backups$history))
   })
 ## End not run
 }

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.show.messages.Rd
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.show.messages.Rd	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.show.messages.Rd	2011-08-03 08:42:56 UTC (rev 3708)
@@ -34,7 +34,7 @@
 \details{
   For \code{rk.show.question}, the R interpreter always waits for the user's choice.
   
-  \code{rk.select.list} replaces \code{utils::select.list} for the running session acting as a drop-in replacement for \code{tk_select.list}. Use \code{.rk.select.list.default} for the original \code{utils::select.list} function (see Examples).
+  \code{rk.select.list} replaces \code{utils::select.list} for the running session acting as a drop-in replacement for \code{tk_select.list}. Use \code{.rk.backups$select.list} for the original \code{utils::select.list} function (see Examples).
 }
 
 \value{
@@ -64,7 +64,7 @@
 ## Selection lists:
 rk.select.list (LETTERS, preselect = c("A", "E", "I", "O", "U"), 
   multiple = TRUE, title = "vowels")
-.rk.select.list.default (LETTERS, preselect = c("A", "E", "I", "O", "U"), 
+.rk.backups$select.list (LETTERS, preselect = c("A", "E", "I", "O", "U"), 
   multiple = TRUE, title = "vowels")
 }
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R	2011-08-01 11:42:25 UTC (rev 3707)
+++ trunk/rkward/rkward/rbackend/rpackages/rkwardtests/R/rkwardtests-internal.R	2011-08-03 08:42:56 UTC (rev 3708)
@@ -210,7 +210,7 @@
 	# This version of rk.set.output.html.file does not notify the frontend of the change. Without this, you'll get lots of output windows.
 	rktest.replace ("rk.set.output.html.file", function (x) {
 		stopifnot(is.character(x))
-		assign(".rk.output.html.file", x, as.environment("package:rkward"))
+		assign(".rk.output.html.file", x, .rk.variables)
 		.rk.do.plain.call ("set.output.file", c (x, "SILENT"), synchronous=FALSE)
 	})
 	assign("initialized", TRUE, envir=.rktest.tmp.storage)


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