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

reticulate output in R chunks not captured in R Markdown #331

Closed
kevinushey opened this issue Aug 10, 2018 · 0 comments · Fixed by #1412
Closed

reticulate output in R chunks not captured in R Markdown #331

kevinushey opened this issue Aug 10, 2018 · 0 comments · Fixed by #1412

Comments

@kevinushey
Copy link
Collaborator

kevinushey commented Aug 10, 2018

To reproduce, try rendering the following document (repro'ed with macOS 10.13.6 + R 3.5.1):

---
title: "Reticulate"
output: md_document
---
  
```{r}
reticulate::py_run_string("print('hello')")
```

You'll see that the printed output (hello) is not captured and reflected in the generated Markdown document.

I think the issue here is that knitr attempts to capture R output with a sink(); however, because we don't always install redirects for Python output back to R, that output is lost. See e.g.:

reticulate/R/output.R

Lines 3 to 11 in 82b2eb8

remap_output_streams <- function() {
output <- import("rpytools.output")
output$remap_output_streams(
write_stdout,
write_stderr,
tty = interactive() || isatty(stdout()),
force = is_windows() && !is_python3()
)
}

The fix here would likely be to ensure that the output streams are remapped when we're running reticulate within knitr -- or perhaps we should just always unconditionally remap the output streams.

See also: rstudio/rstudio#3271

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 a pull request may close this issue.

1 participant