RStudio Connect scheduled reports with trigger

Hi, I was looking if there was a way that a scheduled RStudio Connect report would be sent out only if specific trigger would happen.
We would want to use this for a simple system monitoring report in which a SQL query is ran against couple of databases. In case some pre-defined errors would be found we would like to send those out to recipients.


Great request! There is not a direct way to conditionally send email today. However, there is a workaround:

  1. Setup Connect to run the report on a schedule but NOT distribute results to anyone.
  2. If the condition for sending a report is met, throw an R error using stop
  3. When a scheduled report throws an R error, Connect will email the collaborator automatically.

Thanks we will try this out!

We solved this a bit differently. As the report generates markdown document, we had problems to incorporate stop into this.
Instead we used if (dim(Issues)[1] == 0){q()} which generates error in case trigger is not met. In this case the report will not be sent out. In case the trigger happens (dim(Issues)[1] > 0) the report will be sent out normally.

Curious if there has been any change with this or if this is on a future enhancement list? I'm wanting to schedule my reports to run daily so that anyone can view the most up to date information. I don't want the emails sent daily but instead monthly or weekly to remind those that need encouragement to go look.

I don't think the workaround provided would work because wouldn't want my end users to receive the error email. Maybe other options exist?


R Markdown documents can make their own determination about email sending.

This is described here:

Let's start with an Rmd that is configured to send email after its scheduled execution. Adjust your Rmd to have code like:

if (the_moon_is_not_full) {
    rmarkdown::output_metadata$set(rsc_email_suppress_scheduled = FALSE)

This indicates that the default "email!" behavior is being overridden; email will be suppressed.

You can flip this and start by assuming that mail is not sent. Still start by configuring email-after-scheduling in the UI. Change your Rmd to have:

title: "Report Title"
  rsc_email_suppress_scheduled: false

if (the_moon_is_full) {
    rmarkdown::output_metadata$set(rsc_email_suppress_scheduled = TRUE)

Thank you @aron for pointing that out.
This is perfect, thank you!!

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.