问题
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?
回答1:
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)
```
来源:https://stackoverflow.com/questions/18363757/exporting-and-opening-csvs-using-rmd-file-in-r