Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy/paste table into gmail

Tags:

r

gmail

rstudio

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?

like image 775
Alex Avatar asked Jun 04 '15 00:06

Alex


People also ask

How do I paste an Excel table into Gmail body?

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).

How do I copy and paste a table into an email?

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.


2 Answers

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.

enter image description here

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.

like image 53
A5C1D2H2I1M1N2O1R2T1 Avatar answered Oct 23 '22 03:10

A5C1D2H2I1M1N2O1R2T1


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

like image 1
ronnydw Avatar answered Oct 23 '22 03:10

ronnydw