Skip to content

No complete output for this example of on.exit #1809

@ABohynDOE

Description

@ABohynDOE

In this example of exit handlers the complete output is not shown in the html version of the book.

adv-r/Functions.Rmd

Lines 959 to 974 in 63ea8d9

```{r, error = TRUE}
j06 <- function(x) {
cat("Hello\n")
on.exit(cat("Goodbye!\n"), add = TRUE)
if (x) {
return(10)
} else {
stop("Error")
}
}
j06(TRUE)
j06(FALSE)
```

In the printed version of the book, the output correclty shows

j06(FALSE)
#> Hello
#> Error in j06(FALSE): Error
#> Goodbye!

However, the online version of the book, doesn't print anything after the error is thrown.
When running the function in the R console the "Goodbye" string is indeed printed, but not when doing it in a Rmarkdown document.

Since the whole point of this example was to show that exit handlers do something after a function exits on an error, I think it would be interesting to correct the output on the online version of the book.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions