idemanalyst
idemanalyst

Reputation: 147

Exporting and opening CSVs using .rmd file in R

I'm working on code in R that formats and creates data frames that I want to share using a .rmd file. In my code, I use write.csv and file.show to create and open CSV files of the formatted datasets. Since we are using .rmd to show the code I wrote for formatting, I was wondering if there's a way to also have write.csv and file.show run when someone opens the .rmd file? I've looked around Google and RStudio to see if 1) this is even possible and 2) if it is possible, how to do it, but I haven't found anything. So my question is, is an .rmd file even capable of exporting and opening files, and if so, how do I do it?

Upvotes: 1

Views: 4196

Answers (1)

Remko Duursma
Remko Duursma

Reputation: 2821

Here is an example. It turns out file.show does not work in an Rmd, which shouldn't be too surprising.

This is  atest
========================================================

Make some data

```{r}
df <- data.frame(a=rnorm(10), b=rnorm(10))
```

Write data

```{r}
write.csv(df, "df.csv", row.names=FALSE)
```

Show the data
You will find that this does not work

```{r}
#file.show(df)
#View(df)
```

but this does
```{r}
print(df) 
```

Upvotes: 1

Related Questions