将RStudio的View()输出保存为html

时间:2015-06-02 15:20:47

标签: r rstudio

是否可以将我在RStudio中使用View()命令时看到的页面保存为某些数据作为html文件?

1 个答案:

答案 0 :(得分:5)

也许您的数据看起来像是mtcars数据

data(mtcars)
View(mtcars)

library(xtable)

sink命令将输出发送到文件

sink('somehtmlfile.html')
print(xtable(mtcars),type='html')

然后用

将事情恢复正常
sink()

现在在浏览器中打开somehtmlfile.html