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

error order incorrect #28

Closed
jeroen opened this issue Mar 29, 2013 · 3 comments · Fixed by #139
Closed

error order incorrect #28

jeroen opened this issue Mar 29, 2013 · 3 comments · Fixed by #139
Labels
bug an unexpected problem or unintended behavior

Comments

@jeroen
Copy link
Member

jeroen commented Mar 29, 2013

When running a function that throws plots and then throws an error, the plot appears after the error in the output:

library(evaluate)
test <- function(){
    plot(rnorm(100))
    stop("this is an error!")
}

out <- evaluate("test()")
lapply(out, is)

[[1]]
[1] "source"

[[2]]
[1] "simpleError"

[[3]]
[1] "recordedplot" "oldClass" 
@hadley hadley added the bug an unexpected problem or unintended behavior label Jun 14, 2024
@hadley
Copy link
Member

hadley commented Jun 14, 2024

Looks like this is still a problem.

@hadley
Copy link
Member

hadley commented Jun 16, 2024

Can see this problem in an Rmd/qmd too:

```{r}
#| error: true
test <- function(){
  plot(rnorm(100))
  stop("this is an error!")
}
test()
```

I suspect this is because we can only tell when a plot is complete retrospectively, i.e. after a new plot is created or the code finishes.

...

Or maybe the problem is that the error handler doesn't handle any output before handling the error. If so, that's an easy fix.

@hadley
Copy link
Member

hadley commented Jun 16, 2024

I see the same problem with message() and warning() too. More comprehensive test case:

test <- function(){
  plot(1, main = "one")
  message("this is an message!")
  plot(2, main = "two")
  warning("this is a warning")
  plot(3, main = "three")
  stop("this is an error")
}
test()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants