Exporting and opening CSVs using .rmd file in R

六眼飞鱼酱① 提交于 2021-01-28 08:01:25

问题


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

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