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

tfry at users.sourceforge.net tfry at users.sourceforge.net
Thu Mar 3 16:52:03 UTC 2011


Revision: 3465
          http://rkward.svn.sourceforge.net/rkward/?rev=3465&view=rev
Author:   tfry
Date:     2011-03-03 16:52:03 +0000 (Thu, 03 Mar 2011)

Log Message:
-----------
Add basic plot history support for ggplot2 plots.

Modified Paths:
--------------
    trunk/rkward/ChangeLog
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
    trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R

Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog	2011-03-03 12:33:39 UTC (rev 3464)
+++ trunk/rkward/ChangeLog	2011-03-03 16:52:03 UTC (rev 3465)
@@ -1,3 +1,4 @@
+- Support plot history for ggplot2 plots
 - Be less pro-active about fetching structure information on R objects in the workspace		TODO: verify that this fixes our issues with rXML
 - Allow to browse arbitrarily deeply nested environments in the object browser
 

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2011-03-03 12:33:39 UTC (rev 3464)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R	2011-03-03 16:52:03 UTC (rev 3465)
@@ -46,7 +46,7 @@
 # set from rkward the application:
 # options(device="rk.screen.device")
 
-".rk.preview.devices" <- list ();
+".rk.preview.devices" <- list ()
 
 ".rk.startPreviewDevice" <- function (x) {
 	a <- .rk.preview.devices[[x]]
@@ -76,11 +76,7 @@
 {
 	rk.replace.function ("plot.new", as.environment ("package:graphics"),
 		function () {
-			if (dev.cur() == 1) rk.screen.device ()
-			if (getOption ("rk.enable.graphics.history")) {
-				.callstr <- sys.call (-sys.parents()[sys.nframe ()])
-				rk.record.plot$record (nextplot.pkg = "graphics", nextplot.call = .callstr)
-			}
+			rk.record.plot$.plot.new.hook ()
 			eval (body (.rk.plot.new.default))
 		})
 
@@ -123,16 +119,22 @@
 				invisible ()
 			})
 	)
-	
+
+	setHook (packageEvent ("ggplot2", "attach"),
+		function (...)
+			rk.replace.function ("print.ggplot", as.environment ("package:ggplot2"),
+				function () {
+					## TODO: add specific support for ggplots?
+					rk.record.plot$.plot.new.hook ()
+					eval (body (.rk.print.ggplot.default))
+				})
+	)
+
 	## persp does not call plot.new (), so set a hook. Fortunately, the hook is placed after drawing the plot.
 	setHook ("persp",
 		function (...)
 		{
-			if (dev.cur() == 1) rk.screen.device ()
-			if (getOption ("rk.enable.graphics.history")) {
-				.callstr <- sys.call (-which.max(sys.parents()))
-				rk.record.plot$record (nextplot.pkg = "graphics", nextplot.call = .callstr)
-			}
+			rk.record.plot$.plot.new.hook ()
 		},
 		action = "append"
 	)

Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2011-03-03 12:33:39 UTC (rev 3464)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R	2011-03-03 16:52:03 UTC (rev 3465)
@@ -713,6 +713,13 @@
 		
 		paste (substr (.lab.str, 1, l), "...", sep = "")
 	}
+	.plot.new.hook <- function (.callstr) {
+		if (dev.cur() == 1) rk.screen.device ()
+		if (getOption ("rk.enable.graphics.history")) {
+			.callstr <- sys.call (-sys.parents()[sys.nframe ()])
+			record (nextplot.pkg = "graphics", nextplot.call = .callstr)
+		}
+	}
 	
 	## Utility / R - C++ connection functions:
 	.rk.update.hist.actions <- function (devIds = .hP.names, enable.plot.hist = TRUE)


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