This is probably an easy answer, but I can't find anything online about it. Is there an easy way to copy/paste a table from the R console to an email message?
You can go to Gmail and open a new email, right-click in the mail, and choose Paste (or use the keyboard shortcut CTRL + V).
Click the table move handle to select the table. Do one of the following: To copy the table, press CTRL+C. To cut the table, press CTRL+X.
I would suggest using the Markdown Here extension, available for Chrome and Firefox (the last time I checked). Used in conjunction with kable
from "knitr" (already recommended) you can get a nicely formatted table in seconds.
After installation, you will be able to find a "markdown toggle" option in your right-click context menu when composing an email.
Here's a GIF to show the steps.
Do this often? Save yourself the copying step at least by creating a helper function to write to the clipboard (this is Windows only, but you can expand on the function if you wanted compatibility with other OSes).
gmailTable <- function(indf) writeClipboard(capture.output(knitr::kable(indf)))
Then, in R, just do gmailTable(mtcars)
, switch over to Gmail, paste the contents of the clipboard into the message area, and markdown toggle as before :-)
By the way, "Markdown Here" also lets you use a shortcut to convert whatever is in the message area to HTML. By default, I believe it is ctrl + shift + m.
I would use knitr and kable in RStudio (New file R markdown, output format 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)
```
This example published on RPubs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With