-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathswank-media.R
52 lines (46 loc) · 1.71 KB
/
swank-media.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
makeMediaReplResult <- function(value) {
UseMethod("makeMediaReplResult")
}
makeMediaReplResult.default <- function(value) {
makeReplResult(value)
}
makeMediaReplResult.trellis <- 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.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")
list(quote(`:write-string`), string, quote(`:repl-result`))
}
makeMediaReplResult.complex <- function(value) {
string <- paste(deparse(value), sep="", collapse="\n")
list(quote(`:write-string`), string, quote(`:repl-result`))
}
makeMediaReplResult.array <- function(value) {
makeMediaReplResult.default(value)
}
makeMediaReplResult.matrix <- function(value) {
makeMediaReplResult.default(value)
}
makeMediaReplResult.help_files_with_topic <- function(value) {
output <- capture.output(tools:::Rd2txt(utils:::.getHelpFile(value),
options=list(underline_titles=FALSE)))
string <- paste(output, collapse="\n")
list(quote(`:popup-buffer`), sprintf("*slime-help(%s)*", attr(value, "topic")),
string, quote(`ess-help-mode`))
}
makeReplResultFunction <- makeMediaReplResult