简体   繁体   中英

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?

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) 
```

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM