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

Code/output blocks are split #463

Closed
florisvdh opened this issue May 29, 2024 · 6 comments
Closed

Code/output blocks are split #463

florisvdh opened this issue May 29, 2024 · 6 comments

Comments

@florisvdh
Copy link

Running the following in a bare R console:

reprex::reprex(
  {
    1:4
    2:5
  },
  session_info = TRUE
)

gives:

1:4
#> [1] 1 2 3 4
2:5
#> [1] 2 3 4 5

Created on 2024-05-29 with reprex v2.1.0.9000

Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value
#>  version  R version 4.4.0 (2024-04-24)
#>  os       Linux Mint 21.3
#>  system   x86_64, linux-gnu
#>  ui       X11
#>  language nl_BE:nl
#>  collate  nl_BE.UTF-8
#>  ctype    nl_BE.UTF-8
#>  tz       Europe/Brussels
#>  date     2024-05-29
#>  pandoc   3.1.11 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown)
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package     * version    date (UTC) lib source
#>  cli           3.6.2      2023-12-11 [3] RSPM (R 4.3.0)
#>  digest        0.6.35     2024-03-11 [3] RSPM (R 4.3.0)
#>  evaluate      0.23       2023-11-01 [3] RSPM (R 4.3.0)
#>  fastmap       1.2.0      2024-05-15 [3] RSPM (R 4.4.0)
#>  fs            1.6.4      2024-04-25 [3] RSPM (R 4.3.0)
#>  glue          1.7.0      2024-01-09 [3] RSPM (R 4.3.0)
#>  htmltools     0.5.8.1    2024-04-04 [3] RSPM (R 4.3.0)
#>  knitr         1.46       2024-04-06 [3] RSPM (R 4.3.0)
#>  lifecycle     1.0.4      2023-11-07 [3] RSPM (R 4.3.0)
#>  magrittr      2.0.3      2022-03-30 [3] RSPM (R 4.2.0)
#>  purrr         1.0.2      2023-08-10 [3] RSPM (R 4.2.0)
#>  R.cache       0.16.0     2022-07-21 [3] RSPM (R 4.2.0)
#>  R.methodsS3   1.8.2      2022-06-13 [3] RSPM (R 4.2.0)
#>  R.oo          1.26.0     2024-01-24 [3] RSPM (R 4.3.0)
#>  R.utils       2.12.3     2023-11-18 [3] RSPM (R 4.3.0)
#>  reprex        2.1.0.9000 2024-05-29 [1] Github (tidyverse/reprex@e1f65e9)
#>  rlang         1.1.3      2024-01-10 [3] RSPM (R 4.3.0)
#>  rmarkdown     2.27.1     2024-05-29 [1] Github (rstudio/rmarkdown@e1c93a9)
#>  rstudioapi    0.16.0     2024-03-24 [3] RSPM (R 4.3.0)
#>  sessioninfo   1.2.2      2021-12-06 [3] RSPM (R 4.2.0)
#>  styler        1.10.3     2024-04-07 [3] RSPM (R 4.3.0)
#>  vctrs         0.6.5      2023-12-01 [3] RSPM (R 4.3.0)
#>  withr         3.0.0      2024-01-16 [3] RSPM (R 4.3.2)
#>  xfun          0.44       2024-05-15 [3] RSPM (R 4.4.0)
#>  yaml          2.3.8      2023-12-11 [3] RSPM (R 4.3.0)
#> 
#>  [1] /home/floris/lib/R/library
#>  [2] /usr/local/lib/R/site-library
#>  [3] /usr/lib/R/site-library
#>  [4] /usr/lib/R/library
#> 
#> ──────────────────────────────────────────────────────────────────────────────

Before, {reprex} would keep code and output together in one block. More recently though, R version and rmarkdown versions have changed.

Running knitr::opts_chunk$set(collapse = TRUE) didn't solve it.

@cderv
Copy link
Contributor

cderv commented May 30, 2024

This is an issue with knitr, it seems we missed a breakage for the collapse options

With knitr 1.46

> xfun::raw_string(knitr::knit(text = c("```{r, collapse=TRUE}\n1 + 1\n1:1\n```")))
                                                                                                                                                                

``` r
1 + 1
## [1] 2
```

``` r
1:1
## [1] 1
```

With knitr 1.45

> xfun::raw_string(knitr::knit(text = c("```{r, collapse=TRUE}\n1 + 1\n1:1\n```")))
                                                                                                                                                                

```r
1 + 1
## [1] 2
1:1
## [1] 1
```

I'll fix it on knitr side.

@jennybc
Copy link
Member

jennybc commented May 30, 2024

Thanks @cderv for tracking this down. I will close here and just wait for the fix to appear in a released version of knitr.

@jennybc jennybc closed this as completed May 30, 2024
@hadley
Copy link
Member

hadley commented Jun 14, 2024

I'm seeing this problem again in knitr 1.47:

> packageVersion('knitr')
[1] ‘1.47’
> xfun::raw_string(knitr::knit(text = c("```{r, collapse=TRUE}\n1 + 1\n1:1\n```")))
1/1 [unnamed-chunk-1]

``` r
1 + 1
## [1] 2
```

``` r
1:1
## [1] 1
```

@cderv
Copy link
Contributor

cderv commented Jun 14, 2024

It is fixed in current knitr dev version, which will be knitr 1.48. It has not been released to CRAN yet.

@yihui could you do a knitr release so that this is solved for reprex ?

@yihui
Copy link

yihui commented Jun 14, 2024

Can people wait for two more weeks? I've been exhausted recently. If there's a hurry, I can certainly make the release sooner, but CRAN just complained to me about my last release, so I tend not to make the next release too soon.

@hadley
Copy link
Member

hadley commented Jun 14, 2024

Yeah, no rush from my end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants