-
-
Notifications
You must be signed in to change notification settings - Fork 975
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
[FR] preserve spacing between source code lines in a code block #2220
Comments
You can use the chunk option |
Apologies for violating the issue guidelines. I am surprised I missed the existence of this chunk option when I've read that webpage so many times by now. 😓 |
No worries! That's very normal. I miss information under my nose sometimes, too. |
I think you may have missed it also because this is a side effect of a change in knitr 1.34 which was just released to CRAN https://github.com/yihui/knitr/releases/tag/v1.34
This could probably be qualified as a breaking change and we should probably have communicated this way in our NEWS file to indicated how to put back previous behavior. 😅 Example below: Using version 1.33# renv::install("[email protected]")
packageVersion("knitr")
#> [1] '1.33'
content <- c(
"```{r, collapse=TRUE}",
"x <- 1",
"y <- 2",
"",
"# addition",
"x + y",
"",
"# subtraction",
"x - y"
)
xfun::raw_string(content)
#> ```{r, collapse=TRUE}
#> x <- 1
#> y <- 2
#>
#> # addition
#> x + y
#>
#> # subtraction
#> x - y
res <- knitr::knit(text = content)
xfun::raw_string(res)
#>
#> ```r
#> x <- 1
#> y <- 2
#>
#> # addition
#> x + y
#> #> [1] 3
#>
#> # subtraction
#> x - y
#> #> [1] -1
#> ``` Using 1.34# renv::install("knitr")
packageVersion("knitr")
#> [1] '1.34'
content <- c(
"```{r, collapse=TRUE}",
"x <- 1",
"y <- 2",
"",
"# addition",
"x + y",
"",
"# subtraction",
"x - y"
)
xfun::raw_string(content)
#> ```{r, collapse=TRUE}
#> x <- 1
#> y <- 2
#>
#> # addition
#> x + y
#>
#> # subtraction
#> x - y
res <- knitr::knit(text = content)
xfun::raw_string(res)
#>
#> ```r
#> x <- 1
#> y <- 2
#>
#> # addition
#> x + y
#> #> [1] 3
#> # subtraction
#> x - y
#> #> [1] -1
#> ``` |
Yes, please, let's go with this explanation for why I forgot about that option 😅 |
I suspected in yihui/knitr#2011 that this might be a breaking change, but I didn't realize a breaking case. At this point, I feel |
Yes I missed it too. I also think |
I tried to tackle this but did not find exactly where to apply a modification. Is this done by a knitr hook ? Is there another mechanism ? I created a knitr issue to follow this change |
@IndrajeetPatil we just merged in knitr a change to fix this regression. Thanks for the report! |
Wonderful! Glad that the issue was helpful. :) |
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. |
Description of the issue
When all the source and output blocks from one code chunk are collapsed into a single block, any spaces that were deliberately left to separate different code lines are not preserved in the rendered document.
Source code
Current output
Expected output
The text was updated successfully, but these errors were encountered: