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

Julia code chunks with errors cause rendering to fail even with error=TRUE #2389

Open
paciorek opened this issue Jan 17, 2025 · 1 comment
Open
Labels
custom engine About non R engine external related to other tools or other package

Comments

@paciorek
Copy link

I can use error=TRUE with an R code chunk (or the Quarto style #| error: true), but rendering fails with a Julia code chunk:

---
title: test
engine: knitr
---

```{julia, error=TRUE}
y
```

Here's the error (same thing if I do knit2html("test.qmd").

> rmarkdown::render("test.qmd")


processing file: test.qmd
  |....................................................| 100% [unnamed-chunk-1]Error:
! Error happens in Julia.
UndefVarError: `y` not defined
Stacktrace:
 [1] top-level scope
   @ :0
 [2] eval(m::Module, e::Any)
   @ Core ./boot.jl:385
 [3] macro expansion
   @ /system/linux/lib/R-22.04/4.4.0/x86_64/site-library/JuliaCall/julia/RmdStd.jl:15 [inlined]
 [4] top-level scope
   @ ./none:14
 [5] eval
   @ ./boot.jl:385 [inlined]
 [6] eval_string(x::String)
   @ Main.JuliaCall /system/linux/lib/R-22.04/4.4.0/x86_64/site-library/JuliaCall/julia/setup.jl:203
 [7] docall(call1::Ptr{Nothing})
   @ Main.JuliaCall /system/linux/lib/R-22.04/4.4.0/x86_64/site-library/JuliaCall/julia/setup.jl:176
Backtrace:
  1. rmarkdown::render("test.qmd")
  2. knitr::knit(knit_input, knit_output, envir = envir, quiet = quiet)
  3. knitr:::process_file(text, output)
  6. knitr:::process_group(group)
  7. knitr:::call_block(x)
     ...
 13. JuliaCall:::stdout_capture_command(buffer)
 14. base::tryCatch(...)
 15. base (local) tryCatchList(expr, classes, parentenv, handlers)
 16. base (local) tryCatchOne(...)
 17. value[[3L]](cond)

Quitting from lines 7-8 [unnamed-chunk-1] (test.qmd)
@cderv
Copy link
Collaborator

cderv commented Jan 17, 2025

When using julia with knitr, JuliaCall::eng_juliacall() is used. This engine needs to handle options$error to do the right think in case of error in Julia.

It seems right now, it is not. This is to fix upstream at https://github.com/JuliaInterop/JuliaCall

You should open an issue upstream (and you can ping me if they need help implementing this)

For example, in reticulate for the python engine, they do detect when error should be captured.
https://github.com/rstudio/reticulate/blob/932589f2417968e1da3312dd0b48dba60c058739/R/knitr-engine.R#L221-L225

Right now this is how it works.

@yihui should we try to catch error for any engine when error = TRUE otherwise ?
Possibly here:

knitr/R/block.R

Line 158 in 8a37857

output = in_input_dir(engine(options))

@cderv cderv added external related to other tools or other package custom engine About non R engine labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
custom engine About non R engine external related to other tools or other package
Projects
None yet
Development

No branches or pull requests

2 participants