r-lib / gmailr

Access the Gmail RESTful API from R.
https://gmailr.r-lib.org
Other
229 stars 56 forks source link

Sending R object as an .rds attachment #101

Closed choisy closed 5 years ago

choisy commented 6 years ago

It would be great to be able to send an R object as an RDS attachement to the email.

jimhester commented 5 years ago

You can do this already, e.g.

pkgload::load_all("~/p/gmailr")
#> Loading gmailr
saveRDS(iris, "iris.rds")
draft <- gm_mime() %>%
  gm_from("email@foo.com") %>%
  gm_to("email@bar.com") %>%
  gm_subject("I bought you") %>%
  gm_text_body('Some flowers!') %>%
  gm_attach_file("iris.rds") %>%
  gm_create_draft()

m_draft <- gm_draft(gm_id(draft))
unlink("iris.rds")
# save the attachments locally
gm_save_attachments(m_draft$message)
head(readRDS("iris.rds"))
#>   Sepal.Length Sepal.Width Petal.Length Petal.Width Species
#> 1          5.1         3.5          1.4         0.2  setosa
#> 2          4.9         3.0          1.4         0.2  setosa
#> 3          4.7         3.2          1.3         0.2  setosa
#> 4          4.6         3.1          1.5         0.2  setosa
#> 5          5.0         3.6          1.4         0.2  setosa
#> 6          5.4         3.9          1.7         0.4  setosa

Created on 2019-08-19 by the reprex package (v0.3.0)