Skip to content

Show one line of code but result from another line without adding any comment #2129

Open
@cderv

Description

@cderv

Tested from quarto-dev/quarto-cli#863 (comment)

mtcars
rmarkdown::paged_table(mtcars)

Can I show 'mtcars' in the code chunk after the render but not 'rmarkdown::paged_table(mtcars)' and in addition to that have only the result of the paged_table() shown?

At first I tried

```{r, echo = -2, eval= 2}
mtcars
rmarkdown::paged_table(mtcars)
```

but it will add a ## prefix, without option to opt-out

knitr/R/block.R

Lines 235 to 240 in ca398c2

if (is.numeric(ev <- options$eval)) {
# group source code into syntactically complete expressions
if (isFALSE(options$tidy)) code = sapply(xfun::split_source(code), one_string)
iss = seq_along(code)
code = comment_out(code, '##', setdiff(iss, iss[ev]), newline = FALSE)
}

## mtcars

I would have thought this could be equivalent of this

```{r, eval= FALSE}
mtcars
```

```{r, echo = FALSE}
rmarkdown::paged_table(mtcars)
```

I already encountered this in demo slide when trying to show an example I think. Would it be interesting to add chunk option to allow this ?

Maybe the longer form in two chunks is enough... 🤔

Metadata

Metadata

Assignees

Labels

featureFeature requests

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions