[rkward-cvs] SF.net SVN: rkward-code:[4727] trunk/rkward
tfry at users.sf.net
tfry at users.sf.net
Fri Apr 26 10:36:31 UTC 2013
Revision: 4727
http://sourceforge.net/p/rkward/code/4727
Author: tfry
Date: 2013-04-26 10:36:30 +0000 (Fri, 26 Apr 2013)
Log Message:
-----------
New function rk.capture.device()
Modified Paths:
--------------
trunk/rkward/ChangeLog
trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE
trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
Added Paths:
-----------
trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd
Modified: trunk/rkward/ChangeLog
===================================================================
--- trunk/rkward/ChangeLog 2013-04-26 08:42:16 UTC (rev 4726)
+++ trunk/rkward/ChangeLog 2013-04-26 10:36:30 UTC (rev 4727)
@@ -1,3 +1,5 @@
+- New R function rk.capture.device() for manually embedding graphics devices in RKWard
+ TODO: Adjust frontend error message when embedding fails
- Fixed: R backend would exit immediately, without meaningful error message, if there is an error in .Rprofile (or Rprofile.site)
- Fixed: Installing suggested packages from the package installation dialog was broken
- Fixed: Selecting a mirror via the "R packages" settings page would not work when prompted for package installation form the backend
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE 2013-04-26 08:42:16 UTC (rev 4726)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/NAMESPACE 2013-04-26 10:36:30 UTC (rev 4727)
@@ -9,6 +9,7 @@
export(.rk.cached.available.packages)
export(rk.call.plugin)
export(.rk.callstack.info)
+export(rk.capture.device)
export(.rk.cat.output)
export(rk.clear.plot.history)
export(.rk.data.frame.delete.row)
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R 2013-04-26 08:42:16 UTC (rev 4726)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/internal_graphics.R 2013-04-26 10:36:30 UTC (rev 4727)
@@ -4,32 +4,26 @@
# overriding x11 to get informed, when a new x11 window is opened
#' @export
"rk.screen.device" <- function (...) {
- .rk.do.call ("startOpenX11", as.character (dev.cur ()));
-
args <- list (...)
- if (!exists (".rk.default.device")) {
- if (base::.Platform$OS.type == "unix") {
- device <- grDevices::x11
+ rk.capture.device ({
+ if (!exists (".rk.default.device")) {
+ if (base::.Platform$OS.type == "unix") {
+ device <- grDevices::x11
+ } else {
+ device <- grDevices::windows
+ if (is.null (args[["width"]])) args[["width"]] <- options ("rk.screendevice.width")[[1]]
+ if (!is.numeric (args[["width"]])) args[["width"]] <- 7
+ if (is.null (args[["height"]])) args[["height"]] <- options ("rk.screendevice.height")[[1]]
+ if (!is.numeric (args[["height"]])) args[["height"]] <- 7
+ }
} else {
- device <- grDevices::windows
- if (is.null (args[["width"]])) args[["width"]] <- options ("rk.screendevice.width")[[1]]
- if (!is.numeric (args[["width"]])) args[["width"]] <- 7
- if (is.null (args[["height"]])) args[["height"]] <- options ("rk.screendevice.height")[[1]]
- if (!is.numeric (args[["height"]])) args[["height"]] <- 7
+ device <- .rk.default.device
+ if (is.character (.rk.default.device)) {
+ device <- get (.rk.default.device)
+ }
}
- } else {
- device <- .rk.default.device
- if (is.character (.rk.default.device)) {
- device <- get (.rk.default.device)
- }
- }
- x <- do.call (device, args)
-
- .rk.do.call ("endOpenX11", as.character (dev.cur ()));
-
- rk.record.plot$onAddDevice ()
-
- invisible (x)
+ do.call (device, args)
+ })
}
# Fetch the current size of the given RK() device from the frontend, and redraw
Modified: trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R 2013-04-26 08:42:16 UTC (rev 4726)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/R/public_graphics.R 2013-04-26 10:36:30 UTC (rev 4727)
@@ -113,6 +113,33 @@
invisible (ret) # Current always NULL
}
+#' Capture / embed non-RKWard device windows
+#'
+#' \code{rk.capture.device} evaluates the given expression, and if this has created a window on the screen, tries to embed it as an RKWard window.
+#'
+#' @param expr Expression to evaluate.
+#'
+#' @note Theoretically, \code{expr} can be any valid R expression. However typically this should be calls to X11(), Windows(), or, perhaps dev.copy().
+#' Importantly, the expression should create exactly one new window for \code{rk.capture.device()} to work. Keep in mind, that this is not
+#' always the case for \code{plot(...)} and similar commands, which will re-use an existing plot window, if available. Further, note that
+#' \code{rk.capture.device()} will not work on all platforms (most importantly, not in most MacOSX binaries). Finally, note that a captured
+#' \code{X11()} or \code{Windows} device may look similar to an \code{RK()} device, but is actually a very different thing.
+#'
+#' @seealso \link{RK()}
+#'
+#' @export
+"rk.capture.device" <- function (expr) {
+ oldd <- dev.cur ()
+ .rk.do.call ("startOpenX11", as.character (oldd));
+ on.exit (.rk.do.call ("endOpenX11", as.character (dev.cur())));
+
+ x <- eval.parent (expr)
+
+ if (oldd != dev.cur ()) on.exit (rk.record.plot$onAddDevice (), add=TRUE)
+ else warning ("No device appears to have been created (dev.cur() has not changed)");
+ invisible (x)
+}
+
#' \code{rk.graph.off()} closes the device that was opened by \code{rk.graph.on}.
#'
#' @rdname rk.graph.on
Added: trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd
===================================================================
--- trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd (rev 0)
+++ trunk/rkward/rkward/rbackend/rpackages/rkward/man/rk.capture.device.Rd 2013-04-26 10:36:30 UTC (rev 4727)
@@ -0,0 +1,33 @@
+\name{rk.capture.device}
+\alias{rk.capture.device}
+\title{Capture / embed non-RKWard device windows}
+\usage{
+ rk.capture.device(expr)
+}
+\arguments{
+ \item{expr}{Expression to evaluate.}
+}
+\description{
+ \code{rk.capture.device} evaluates the given expression,
+ and if this has created a window on the screen, tries to
+ embed it as an RKWard window.
+}
+\note{
+ Theoretically, \code{expr} can be any valid R expression.
+ However typically this should be calls to X11(),
+ Windows(), or, perhaps dev.copy(). Importantly, the
+ expression should create exactly one new window for
+ \code{rk.capture.device()} to work. Keep in mind, that
+ this is not always the case for \code{plot(...)} and
+ similar commands, which will re-use an existing plot
+ window, if available. Further, note that
+ \code{rk.capture.device()} will not work on all platforms
+ (most importantly, not in most MacOSX binaries). Finally,
+ note that a captured \code{X11()} or \code{Windows}
+ device may look similar to an \code{RK()} device, but is
+ actually a very different thing.
+}
+\seealso{
+ \link{RK()}
+}
+
More information about the rkward-tracker
mailing list