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

Throw an error if inline result is not coercible to character #2007

Merged
merged 5 commits into from
May 28, 2021

Conversation

cderv
Copy link
Collaborator

@cderv cderv commented May 28, 2021

This fix #2006

  • any inline result will be coerced to character by as.character()
  • If this result in an error, we catch it a thow our own error with a helpful message.

I wanted to indicate the line in the error message but it seems for inline code we don't actually get the location in the file I expected. So I just added the inline code that errors in the message. It is a start.

With this example

---
output:
  html_document: default
---

Sentence with inline `r function() "function"`.

from the original issue in rmarkdown, we now get

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


processing file: test.Rmd
  |.............................................................................................| 100%
   inline R code fragments

Quitting from lines 2-9 (test.Rmd) 
Error: Result is not coercible to character in this inline code: 'function() "function"'

Note that the lines indicated are not so useful because it is the all files. Contrary to code block, inline code are not exactly located on a line number.

Ideas from improvement for inline code chunk:

Quitting from lines 6 (test.Rmd) 
Error: Result is not coercible to character in inline code line 6: 'function() "function"'

First line above is from all code proccessing (block an inline).
Second block is from inline execution only.

Anyway, this could be for another time

Also, I added unit test for this and a NEWS item as Major Changes as potential breaking change

@cderv cderv requested a review from yihui May 28, 2021 13:57
Copy link
Owner

@yihui yihui left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

R/block.R Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
@yihui yihui added this to the v1.25 milestone May 28, 2021
@yihui yihui added the next Issues/PRs considered for the next release label May 28, 2021
Co-authored-by: Yihui Xie <xie@yihui.name>
Co-authored-by: Yihui Xie <xie@yihui.name>
@cderv
Copy link
Collaborator Author

cderv commented May 28, 2021

In fact knitr-example is failing but not sure this is related... 🤔
https://github.com/yihui/knitr/runs/2695278091#step:11:1711

Do you see what would be the cause ? Is it an external change ?

Maybe I should schedule a weekly run on knitr-examples repo so that we know if the master branch break due to external change.

@yihui
Copy link
Owner

yihui commented May 28, 2021

Do you see what would be the cause ? Is it an external change ?

Yes, it's because of a change in formatR: https://github.com/yihui/formatR/releases/tag/v1.10 Comments that are wrapped may become narrower than before. I just committed the change to knitr-examples.

Maybe I should schedule a weekly run on knitr-examples repo so that we know if the master branch break due to external change.

That sounds good to me.

@yihui yihui merged commit 89a1f6c into master May 28, 2021
@yihui yihui deleted the fix/latex-inline-hook branch May 28, 2021 19:33
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
next Issues/PRs considered for the next release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

non LATEX inline hook evaluate a function whereas it is not expected
2 participants