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

line information for errors with inline chunks is incorrect #2387

Closed
3 tasks done
kevinushey opened this issue Jan 7, 2025 · 4 comments
Closed
3 tasks done

line information for errors with inline chunks is incorrect #2387

kevinushey opened this issue Jan 7, 2025 · 4 comments
Labels
next Issues/PRs considered for the next release

Comments

@kevinushey
Copy link

kevinushey commented Jan 7, 2025

Consider a file with the contents:

---
title: "Title"
format: html
---

This is some text.

This is a line with an inline chunk, which errors. `r print(ouch)`

This is some more text.

If I knit this document with knitr::knit("example.Rmd"), I see:

processing file: example.Rmd
  |......................................................................| 100%Error:
! object 'ouch' not found
Backtrace:
 1. base::print(ouch)



Quitting from lines 2-10 (example.Rmd)
                                                                                          
Execution halted

The lines for the error printed, "Quitting from lines 2-10 (example.Rmd)", are rather non-specific. Would it be possible to better report the line where this error occurred?

Also, as an aside: is it expected that the "Error:" printout here is placed on the same line as the progress bar?

> xfun::session_info('knitr')
R version 4.4.2 (2024-10-31)
Platform: aarch64-apple-darwin20
Running under: macOS Sequoia 15.2

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  evaluate_1.0.1  graphics_4.4.2  grDevices_4.4.2 highr_0.11
  knitr_1.49.3    methods_4.4.2   stats_4.4.2     tools_4.4.2
  utils_4.4.2     xfun_0.50       yaml_2.3.10

By filing an issue to this repo, I promise that

  • I have fully read the issue guide at https://yihui.org/issue/.
  • I have provided the necessary information about my issue.
    • If I'm asking a question, I have already asked it on Stack Overflow or RStudio Community, waited for at least 24 hours, and included a link to my question there.
    • If I'm filing a bug report, I have included a minimal, self-contained, and reproducible example, and have also included xfun::session_info('knitr'). I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version: remotes::install_github('yihui/knitr').
    • If I have posted the same issue elsewhere, I have also mentioned it in this issue.
  • I have learned the Github Markdown syntax, and formatted my issue correctly.

I understand that my issue may be closed if I don't fulfill my promises.

@kevinushey kevinushey reopened this Jan 7, 2025
@kevinushey
Copy link
Author

Interestingly, the error line appears to be correct if there is a real chunk used before the inline chunk, e.g.

---
title: "Title"
format: html
---

This is some text.

```{r}
#| label: hello-world
print(1 + 1)
```

This is a line with an inline chunk, which errors. `r print(ouch)`

This is some more text.

which gives

> knitr::knit("example.Rmd")


processing file: example.Rmd
Warning: Duplicated chunk option(s) 'label' in both chunk header and pipe comments of the chunk 'hello-world'.
  |........................................................| 100%              Error:
! object 'ouch' not found
Backtrace:
 1. base::print(ouch)

Quitting from lines 13-15 (example.Rmd)

although then I see the strange spurious warning regarding a duplicated label?

Repository owner deleted a comment from Jeffinp Jan 8, 2025
yihui added a commit to yihui/litedown that referenced this issue Jan 8, 2025
… consist of a single chunk, in which case the error location would not be printed
@yihui
Copy link
Owner

yihui commented Jan 8, 2025

Would it be possible to better report the line where this error occurred?

I think this is doable, and I'll do it. Actually I have already done it in litedown:

---
title: "Title"
format: html
---

This is some text.

This is a line with an inline chunk, which errors. `{r} print(ouch)`

This is some more text.
> litedown::fuse('test.Rmd')
Error in eval(expr, fuse_env()) : object 'ouch' not found
Quitting from test.Rmd#8:53-8:67

The line/column numbers of the inline code will be printed (and in RStudio, users can click on the message to go to the exact location of the inline code).

Also, as an aside: is it expected that the "Error:" printout here is placed on the same line as the progress bar?

Currently it is, but I agree it will look better if the error message starts on a new line.

although then I see the strange spurious warning regarding a duplicated label?

That's a bug. I just fixed it. Thanks!

@yihui yihui added the next Issues/PRs considered for the next release label Jan 8, 2025
yihui added a commit that referenced this issue Jan 9, 2025
…the error message can be displayed on a new line (#2387)
@yihui yihui closed this as completed in 85c62f4 Jan 9, 2025
@yihui
Copy link
Owner

yihui commented Jan 9, 2025

All done.

> knitr::knit('example.Rmd')


processing file: example.Rmd
  |................................................................| 100%

Error:
! object 'ouch' not found
Backtrace:
 1. base::print(ouch)

Quitting from lines 8-8 (example.Rmd)

@kevinushey
Copy link
Author

Awesome -- thanks @yihui!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next Issues/PRs considered for the next release
Projects
None yet
Development

No branches or pull requests

2 participants