-
Notifications
You must be signed in to change notification settings - Fork 346
Description
Reported in
and full example at
Problem
Currently, results = 'hide' does not seem to be handled by reticulate's knitr engine. Example:
---
title: "Test report"
output: html_document
---
```{r, results = 'hide'}
class MyClass:
def _repr_html_(self):
return "<p>uh-oh</p>"
MyClass()
```The results will still be shown. This is a minimal example - see posit-dev/great-tables#291 for one with great_tables
Context
This is because _repr_html_ is catched to be returned as a knitr::raw_html()
Lines 744 to 750 in d4e752b
| } else if (isHtml && py_has_method(value, "_repr_html_")) { | |
| py_capture_output({ | |
| data <- as_r_value(value$`_repr_html_`()) | |
| }) | |
| .engine_context$pending_plots$push(knitr::raw_html(data)) | |
| return("") |
and provided in the
out component on which knitr:::sew() will applyLines 626 to 628 in d4e752b
| eng_python_wrap <- function(outputs, options) { | |
| knitr::engine_output(options, out = outputs) | |
| } |
By returning engine_output(out = ), knitr's assumes the output is already filtered with what should be filtered.
Otherwise, it will be handled directly engine_output() default usage
https://github.com/yihui/knitr/blob/ba8d9fb0ecd60f3f9ebec58fdde1e689bdc40ad3/R/engine.R#L96-L98
So I do think reticulate needs to support results = 'hide' and not provide outputs in the list when the option is provided.
I can make a PR - just need to think about the best place to do this.