Skip to content

knitr should interact better with system (R) #1203

@MichaelChirico

Description

@MichaelChirico

As highlighted by this question, we sort of have to jump through hoops to get the output from a system call to print its output to HTML.

Consider the following simple .Rmd file:


---
output: html_document

---

```{r test, echo = TRUE}
system("ls")
```

The output of which is simply:

system("ls")

We can force the output to show up by hiding things from viewers:


---
output: html_document

---

```{r test, echo = TRUE, eval = FALSE}
system("ls")
```
```{r test_eval, echo = FALSE, eval = TRUE}
cat(system("ls", intern = TRUE), collapse = "\n")
```

Which produces the output one would expect from simply running the first chunk.

But this seems like a sub-optimal solution and I think runs antithetical to the spirit of knitr.

I'm not 100% sure this is a knitr problem (as opposed to an rmarkdown problem); please advise if so.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions