Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R Markdown: How do I show file contents

Tags:

r

rstudio

knitr

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.

like image 489
JerryKur Avatar asked Mar 25 '15 14:03

JerryKur


People also ask

How do I view an R Markdown file?

To open a new file, click File > New File > R Markdown in the RStudio menu bar. A window will pop up that helps you build the YAML frontmatter for the . Rmd file. Use the radio buttons to select the specific type of output that you wish to build.

How do you add a table of contents to a RMD?

You can embed an R code chunk like this: ```{r} summary(cars) ``` You can also embed plots, for example: ```{r, echo=FALSE} plot(cars) ``` ### Header 3 Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot. I tried running this in RStudio v 0.98.

How do I get headings in R Markdown?

We can insert headings and subheadings in R Markdown using the pound sign # . There are six heading/subheading sizes in R Markdown. The number of pound signs before your line of text determines the heading size, 1 being the largest heading and 6 being the smallest.

How do you preview Markdown in RStudio?

You can preview your file by using the shortcut shift + ctrl + k on rmarkdown::render("file. Rmd", params = "ask") (or shift + command + k for Mac).


1 Answers

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.

like image 191
Yihui Xie Avatar answered Sep 18 '22 17:09

Yihui Xie