Christophe Weblog Wiki Code Publications Music
use a similar repl result method in swank-media.R for ggplot objects
authorChristophe Rhodes <csr21@cantab.net>
Fri, 9 Sep 2011 20:46:01 +0000 (21:46 +0100)
committerChristophe Rhodes <csr21@cantab.net>
Fri, 9 Sep 2011 20:46:01 +0000 (21:46 +0100)
Should refactor (and provide width/height options)

swank-media.R

index 686a6368b1a52647bf0801f4a2b6dd4c4c74963e..01ea682932cf6bee1c5718c513301d906360ca74 100644 (file)
@@ -15,6 +15,15 @@ makeMediaReplResult.trellis <- function(value) {
                                         quote(`:file`), filename)),
        deparse(value$call, nlines=1))
 }
+makeMediaReplResult.ggplot <- function(value) {
+  filename <- tempfile("swank-media-")
+  png(filename, width=320, height=200)
+  print(value)
+  dev.off()
+  list(quote(`:write-image`), list(list(quote(`:type`), quote(png),
+                                        quote(`:file`), filename)),
+       deparse(value$call, nlines=1))
+}
 
 makeMediaReplResult.numeric <- function(value) {
   string <- paste(deparse(value), sep="", collapse="\n")