JerryKur
JerryKur

Reputation: 7519

R Markdown: How do I show file contents

I want to dump the contents of a text file inside my R markdown (rmd). I tried using the R command: system("cat a.csv"). This command show the file contents in R, but produces no output when I knit the file in R studio.

Upvotes: 15

Views: 9772

Answers (1)

Yihui Xie
Yihui Xie

Reputation: 30174

You can use either

```{r engine='bash', comment=''}
cat a.csv
```

or

```{r comment=''}
cat(readLines('a.csv'), sep = '\n')
```

The former solution requires Bash. The latter one is pure R.

Upvotes: 29

Related Questions