evaluate icon indicating copy to clipboard operation
evaluate copied to clipboard

Not all output is captured?

Open jankatins opened this issue 8 years ago • 1 comments

In irkernel, we got a bugreport (https://github.com/IRkernel/IRkernel/issues/184) that not all output is captured and we use evaluate under the hood to implement the kernel.

In this case it is a call to ggplot:

library(evaluate)

code <- "library(ggplot2)
data <- data.frame(x = letters[1:5], y = runif(5))
ggplot(data, aes(x, y)) + geom_bar()
"

l = list()
txt <- function(o, type) {
  t <- paste(o, collapse = '\n')
  t <- paste("OUT: ", t)
  l[length(l)+1] <<- paste("T: ",Sys.time()," type: ", type, "  -> ", t)
}
oh <- new_output_handler(source = identity, 
                         text = function(o) txt(o, "text"), 
                         graphics = identity,
                         message = function(o) txt(o, "message"), 
                         warning = function(o) txt(o, "warn"), 
                         error = function(o) txt(o, "error"), 
                         value = identity)



x <- evaluate(code, output_handler = oh)
l

This currently results in in empty list l, but when I run the code directly in an rstudio console:

> library(ggplot2)
> data <- data.frame(x = letters[1:5], y = runif(5))
> ggplot(data, aes(x, y)) + geom_bar()
Error : Mapping a variable to y and also using stat="bin".
  With stat="bin", it will attempt to set the y value to the count of cases in each group.
  This can result in unexpected behavior and will not be allowed in a future version of ggplot2.
  If you want y to represent counts of cases, use stat="bin" and don't map a variable to y.
  If you want y to represent values in the data, use stat="identity".
  See ?geom_bar for examples. (Defunct; last used in version 0.9.2)

jankatins avatar Dec 16 '15 10:12 jankatins

@JanSchulz could you please start adding language tags to your code blocks for syntax highlighting? it’s easier to read that way. for R, simply start your code blocks with ````r`

flying-sheep avatar Dec 19 '15 17:12 flying-sheep

Closing this since it's been ~8 years and you've presumably figured it out, but I suspect it's something to do with the implicit print that is needed to accurately generate the message since adding an explicit print() makes the problem go away. (i.e. it might be a problem with your custom output handler)

hadley avatar Jun 14 '24 18:06 hadley