Rmarkdown not outputting results of system command to html file

孤街醉人 提交于 2019-12-01 17:35:56

Use intern = TRUE for system(), then cat() the output:

cat(system(paste("head -n5", datafile), intern = TRUE), sep = '\n')

Using a bash chunk in the Rmarkdown document does the job for me. For example with the package testdat which has .csv file in its extdata directory:

```{bash}
head -n5 ~/R/x86_64-pc-linux-gnu-library/3.3/testdat/extdata/2012.csv
```

will give in your html file:

## 14,,2012,Censo,1775351,,
## 14,,2012,Votantes,1135568,64.0,
## 14,,2012,Nulos,9168,0.8,
## 14,,2012,Válidos,1126400,99.2,
## 14,,2012,Blancos,14640,1.3,

I am not sure though this option existed in 2014 when you've asked the question.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!