Copy/paste table 进入 gmail

Copy/paste table into gmail

这可能是一个简单的答案,但我在网上找不到任何相关信息。有没有一种从 R 控制台到电子邮件的 copy/paste a table 的简单方法?

在 RStudio 中,您可以使用 View(table) 并突出显示整个 window 并将其粘贴到您的电子邮件中。 cars 数据集对我来说是这样的:

我唯一能想到的是要么进入 knitr/xtable/latex,要么将要显示的 data.frame 保存为 csv 文件,然后将其作为电子邮件附件发送。第一个选项仅需要一个 table 就需要付出很多努力,但如果您认为您可能更频繁地需要这种东西,那么花时间可能是值得的。

我会在 RStudio 中使用 knitr 和 kable(新文件 R markdown,输出格式 html):

---
title: "attaching pretty R tables to your gmail message"
date: "4 Jun 2015"
output: html_document
---

This is an example of a pretty table, produced with Knitr in RStudio:

 * RStudio: New file R markdown, output format html
 * open in (chrome) browser
 * save as complete html
 * attach the html to your gmail message

```{r kable}
library(knitr)
carstable = head(mtcars)
kable(carstable)
```

这个例子published on RPubs

我建议使用 Markdown Here 扩展,可用于 Chrome 和 Firefox(我上次检查时)。与 "knitr" 中的 kable 结合使用(已推荐),您可以在几秒钟内获得格式良好的 table。

安装后,您将能够在撰写电子邮件时在右键单击上下文菜单中找到 "markdown toggle" 选项。

这是一张显示步骤的 GIF。

经常这样做吗?至少通过创建一个写入剪贴板的辅助函数来节省复制步骤(这只是 Windows,但如果你想与其他操作系统兼容,你可以 expand on the function)。

gmailTable <- function(indf) writeClipboard(capture.output(knitr::kable(indf)))

然后,在 R 中,只需执行 gmailTable(mtcars),切换到 Gmail,将剪贴板的内容粘贴到消息区域,然后像以前一样切换 markdown :-)

顺便说一下,"Markdown Here" 还允许您使用快捷方式将消息区域中的任何内容转换为 HTML。默认情况下,我相信它是 ctrl + shift + m.