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

Inline code chunks are broken by linebreaks #655

Closed
aammd opened this issue Nov 4, 2013 · 12 comments
Closed

Inline code chunks are broken by linebreaks #655

aammd opened this issue Nov 4, 2013 · 12 comments
Labels
feature Feature requests
Milestone

Comments

@aammd
Copy link

aammd commented Nov 4, 2013

When a .Rmd file is written in a text editor that wraps lines at a ruler, sometimes a linebreak falls in the middle of an inline code chunk. This causes an error when the document is knit. Is it possible to modify knitr to ignore linebreaks in inline code chunks?

Also see http://stackoverflow.com/q/19819972/559676

@yihui yihui closed this as completed in 3adaa02 Nov 5, 2013
@yihui
Copy link
Owner

yihui commented Nov 5, 2013

should be fixed now; please test the current development version: https://github.com/yihui/knitr#readme

@krlmlr
Copy link
Contributor

krlmlr commented Nov 5, 2013

Doesn't seem to work, see commit above in https://github.com/krlmlr/knitr-examples/tree/655-inline-linebreak

@yihui
Copy link
Owner

yihui commented Nov 5, 2013

Interesting. It works for me.

@krlmlr
Copy link
Contributor

krlmlr commented Nov 5, 2013

Well, just tested with fresh code from your master:

./k 107-inline-linebreak.Rmd
Error in base::parse(text = code, srcfile = NULL) : 
  3:0: unexpected end of input
1: paste("to span",
2: #' "over several lines")
  ^
[1] "107-inline-linebreak.md"

Cleaned the cache up front, too...

@yihui
Copy link
Owner

yihui commented Nov 5, 2013

I see. That is an R script for spin(), not really an Rmd file. An Rmd file should be this:

Inline expressions such as `r "the following"` are now allowed `r paste("to span",
"over several lines")`.

yihui added a commit to yihui/knitr-examples that referenced this issue Nov 5, 2013
example for inline expression spanning several lines (yihui/knitr#655)
@aammd
Copy link
Author

aammd commented Nov 6, 2013

It works for my source code, and example 107 -- but only if the \n does NOT fall exactly after the `r at the start of the inline code.

Inline expressions such as `r "the following"` are now allowed `r
 paste("to span","over several lines")`.

doesn't work.

@yihui
Copy link
Owner

yihui commented Nov 6, 2013

@aammd Now I remember why I disallowed line breaks in the past; that is because sometimes we may write a plain R code block

```r
1 + 1
```

which is not supposed to be evaluated. In this case, allowing line breaks for inline expressions can be troublesome, because such a code block may be identified as an inline expression when you have a space after r.

```r[space_here]
1 + 1
```

Anyway, I think it should be reasonable to support line breaks inside an inline expression, but not in the beginning of an expression.

@krlmlr I believe unit tests are more appropriate, instead of writing examples for each document format, because the examples are very short.

@krlmlr
Copy link
Contributor

krlmlr commented Nov 6, 2013

Unfortunately, most automatic word wrappers don't know about this specialty, and would also wrap just after r if it fits. Can this be solved using a negative lookbehind?

Also, what about Rnw files and \Sexpr{}?

@yihui
Copy link
Owner

yihui commented Nov 7, 2013

\Sexpr{} is different. I require a space after r in markdown because it is rare for one to write r that is not supposed to be an inline code expression. For \Sexpr{}, it is not necessary to require a space, because it is simply not a valid LaTeX command at all.

Looking behind is certainly possible, but it will probably make R Markdown an exception in the parser, because I'll have to use Perl regular expressions. I do not have much brain power to think about this at the moment, for reasons that you know :)

@isomorphisms
Copy link

I'm still getting this error, apparently a couple years after the fix. rmarkdown::render("my file.Rmd", "my file.html") is my incantation.

@yihui
Copy link
Owner

yihui commented Jul 15, 2015

@isomorphisms A minimal reproducible example please. This works for me:

aaa `r 1+
1` bbb

gadenbuie added a commit to gadenbuie/knitr that referenced this issue Jul 13, 2017
Does not flag code chunks as inline when a line starts with three backticks
yihui pushed a commit that referenced this issue Jul 13, 2017
…#1416)

* Add neg-lookback to md inline pattern (#655)

Does not flag code chunks as inline when a line starts with three backticks

* Add name and news item for PR #1416
@github-actions
Copy link

This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature Feature requests
Projects
None yet
Development

No branches or pull requests

4 participants