Skip to content

Commit ade956c

Browse files
authored
Correctly handles htmlwidgets passed in inline R code (#4604)
* fix sew.knit_asis behavior for inline R code - if options missing, it needs to be missing in the method call - Add tests - require a dev version of knitr for our tests to pass (for yihui/knitr#2237) * [tests tools] Update helper script for quiet output
1 parent 877de71 commit ade956c

File tree

4 files changed

+39
-4
lines changed

4 files changed

+39
-4
lines changed

src/resources/rmd/patch.R

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,14 @@ if (utils::packageVersion("knitr") >= "1.32.8") {
133133
} else if (inherits(x, "knit_asis")) {
134134
# delegate
135135
is_html_widget <- inherits(x, "knit_asis_htmlwidget")
136-
x <- knitr:::sew.knit_asis(x, options, ...)
136+
# knit_asis method checks on missing options which
137+
# it gets in knitr because UseMethod() is called in generic
138+
# but here we pass our default empty list options
139+
x <- if (missing(options)) {
140+
knitr:::sew.knit_asis(x, ...)
141+
} else {
142+
knitr:::sew.knit_asis(x, options, ...)
143+
}
137144

138145
# if it's an html widget then it was already wrapped
139146
# by add_html_caption
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
format: html
3+
_quarto:
4+
tests:
5+
html:
6+
ensureHtmlElements:
7+
- ["#in-chunk div.datatables", "#inline div.datatables"]
8+
- []
9+
---
10+
11+
## In-chunk {#in-chunk}
12+
13+
htmlwidgets should work in chunk
14+
15+
```{r dt}
16+
#| echo: false
17+
#| message: false
18+
carsDT <- DT::datatable(cars)
19+
carsDT
20+
```
21+
22+
## Inline {#inline}
23+
24+
and inline
25+
26+
`r carsDT`
27+
28+

tests/new-smoke-all-test.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ cd $smokeAllFolder
1010

1111
function CheckCreateAndEnter([string]$folder) {
1212
If (-Not (Test-Path -Path $folder)) {
13-
mkdir $folder
13+
$null = mkdir $folder
1414
}
1515
cd $folder
1616
}

tests/renv.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,9 +702,9 @@
702702
"RemoteUsername": "yihui",
703703
"RemoteRepo": "knitr",
704704
"RemoteRef": "master",
705-
"RemoteSha": "78f1db5c32e59c85e06f9704ab7b22a459c2b945",
705+
"RemoteSha": "db4eafb3e05939c6d8e558cf66665a4669ee0bbc",
706706
"RemoteHost": "api.github.com",
707-
"Hash": "f83defa969149ac30ff836162d56e894",
707+
"Hash": "9acfef646b3349e9853fdfb1181707ec",
708708
"Requirements": [
709709
"evaluate",
710710
"highr",

0 commit comments

Comments
 (0)