DEV Community

Cover image for How to Automate Daily Reports Using R, R Markdown, and Cron
Cristiano Gabrieli
Cristiano Gabrieli

Posted on

How to Automate Daily Reports Using R, R Markdown, and Cron

R for Automation: How to Build a Daily Report Generator with R Scripts
Automation is one of the most underrated uses of R.
Most teams still generate daily reports manually β€” exporting CSVs, copying charts, formatting tables, and emailing everything by hand. It’s slow, repetitive, and prone to mistakes.

In this guide, you’ll learn how to build a clean, reliable daily report generator using:

R scripts

R Markdown

a simple scheduler (cron or Task Scheduler)
Once set up, the report runs automatically every morning without any manual work.

πŸš€ Why automate reports with R
R is perfect for automation because it can:

pull fresh data from files, APIs, or databases

generate HTML or PDF reports

create charts and KPIs

send emails

run on a schedule

This turns R into a lightweight reporting engine for your team.

πŸ“ 1. Project structure
A clean folder structure keeps everything organized:

Code
daily-report/
β”œβ”€β”€ data/
β”œβ”€β”€ scripts/
β”‚ └── generate_report.R
β”œβ”€β”€ report/
β”‚ └── template.Rmd
β”œβ”€β”€ output/
└── config.yml
template.Rmd β†’ your report layout

generate_report.R β†’ the automation script

output/ β†’ where daily reports are saved

πŸ“„ 2. Create the R Markdown report template
Inside report/template.Rmd:

yaml

title: "Daily Report"
output: html_document
params:

report_date: !r Sys.Date()

Then add your content:

summary tables

ggplot charts

KPIs

text commentary

R Markdown will render this into a clean HTML report.

🧠 3. Write the automation script
Inside scripts/generate_report.R:

r
library(rmarkdown)
library(glue)

today <- Sys.Date()

render(
input = "report/template.Rmd",
output_file = glue("../output/report_{today}.html"),
params = list(report_date = today)
)
This script:

loads the template

injects today’s date

generates a new report file

saves it in /output

You can run it manually or schedule it.

πŸ“¬ 4. Optional: email the report automatically
If you want the report emailed to your team:

r
library(blastula)

email <- compose_email(
body = md("Your daily report is ready.")
)

smtp_send(
email,
from = "reports@yourdomain.com",
to = "team@company.com",
subject = "Daily Report",
credentials = creds_file("smtp_creds")
)
This turns your script into a full reporting pipeline.

⏰ 5. Schedule the automation
Windows Task Scheduler
Create a task:

Trigger: Daily at 07:00

Action:

Code
Rscript.exe "C:/path/to/scripts/generate_report.R"
macOS / Linux (cron)
Code
0 7 * * * Rscript /path/to/scripts/generate_report.R
Now the report runs every morning automatically.

βœ… Final thoughts
This workflow is simple, reproducible, and easy to maintain.
Once you automate your daily reports, you eliminate repetitive work and free up time for real analysis.

You can extend this setup with:

API data pulls

SQL queries

PDF output

Slack notifications

dashboards

R becomes your personal reporting engine.

Top comments (0)