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

Ensure flexdashboard respects knitr's collapse option #428

Merged
merged 5 commits into from
Mar 3, 2023

Conversation

gadenbuie
Copy link
Member

@gadenbuie gadenbuie commented Mar 1, 2023

Fixes #102

Previously, flexdashboard was co-opting knitr's internal chunk hook. We now instead first call knitr's default chunk hook before applying flexdashboard's customized chunk hook.

Testing

The document below includes two R chunks that are either collapsed or not-collapsed and two figures (to demonstrate we haven't affected the figure syntax).

Before

Messages collapsed

After

Messages collapsed

Diff

Comparing the pre-rendered HTML output before and after the change (on the chunk with collapse = TRUE) shows that we've only affected the output. (FYI the diff is from a version with echo = FALSE.)

   <div class="knitr-options" data-fig-width="576" data-fig-height="460">
   
   </div>
-  <pre><code>[1] TRUE</code></pre>
-  <pre><code>[1] &quot;a&quot;</code></pre>
-  <pre><code>[1] &quot;b&quot;</code></pre>
+  <pre><code>[1] TRUE
+  [1] &quot;a&quot;
+  [1] &quot;b&quot;</code></pre>
knitr-collapse.Rmd
---
title: 'Messages collapsed'
output:
  flexdashboard::flex_dashboard:
    orientation: row
---

## Row

### Collapsed

```{r echo = TRUE, collapse = TRUE, message = TRUE, comment = "#>"}
knitr::opts_current$get("collapse")
print("a")
print("b")
```

### Not collapsed

```{r echo = TRUE}
print("c")
print("d")
```

## Row

### A wide plot

```{r, fig.width=10, fig.height=5}
hist(faithful$waiting)
```

### A tall plot

```{r, fig.width=5, fig.height=10}
hist(faithful$waiting)
```

NEWS.md Outdated Show resolved Hide resolved
@gadenbuie gadenbuie merged commit 7e5c636 into main Mar 3, 2023
@gadenbuie gadenbuie deleted the fix/102-knitr-collapse branch March 3, 2023 15:45
cpsievert added a commit that referenced this pull request Mar 3, 2023
@cpsievert cpsievert mentioned this pull request Mar 3, 2023
cpsievert added a commit that referenced this pull request Mar 3, 2023
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

Successfully merging this pull request may close these issues.

knitr option collaspe is not honoured
2 participants