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.
1 Answer
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.
-
It is close, but with either command each line of the output is prefixed with '## '. How can get rid of these characters.– JerryKurMar 27, 2015 at 0:46
-
5@JerryKur Have you really tried what I wrote above? I think I have indicated
comment=''
in my answer. Mar 27, 2015 at 1:50 -
1Thanks again. I did not understand that the comment='' was critical.– JerryKurMar 27, 2015 at 4:16
readLines()
to show N lines.