Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not all output is captured? #60

Closed
jankatins opened this issue Dec 16, 2015 · 2 comments
Closed

Not all output is captured? #60

jankatins opened this issue Dec 16, 2015 · 2 comments

Comments

@jankatins
Copy link

In irkernel, we got a bugreport (IRkernel/IRkernel#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)
@flying-sheep
Copy link
Contributor

@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`

@hadley
Copy link
Member

hadley commented Jun 14, 2024

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 hadley closed this as completed Jun 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants