Using blastula to send multiple emails from RStudio Connect

I would like to use blastula to send a set of multiple emails based on the result of an RStudio Connect report. I have been following the instructions from this blog post and I am able to get the report to send a single email based on one row of a data frame data_frame using code like this:

render_connect_email(input = "email_test.Rmd",
                       render_options = list(params = list(member = data_frame$member_id[i]))) %>% 
    attach_connect_email(subject = "Email test")

I would like to be able to loop through data_frame and send one email for each row, like so:

for (i in 1:nrow(data_frame)) {
  render_connect_email(input = "email_test.Rmd",
                       render_options = list(params = list(member = data_frame[i]))) %>% 
    attach_connect_email(subject = "Email test")
}

When I publish this, however, I only receive an email based on the value of the last row in the data frame, i.e. i = nrow(data_frame). Knitting provides me a rendered version of all of the emails, but RStudio Connect only sends the last one. Is there a way to send multiple emails via Connect, or can it only send one email per report?

Hi!
I've accomplished this using purrr::map(). Give this a try rather than your for loop. It will take the form of:
purrr::map(.x = <your_distribution_list>, ~render_connect_email())

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.