By Marco Pasin
R Markdown is an amazing tool that allows you to blend bits of R code with ordinary text and produce well-formatted data analysis reports very quickly. You can export the final report in many formats like HTML, pdf or MS Words which makes it easy to share with others. And of course, you can modify or update it with fresh data very easily.
I have recently been using it R Markdown for pulling data from various data source such Google Analytics API and MySQL database, perform several operations on it (merging for example) and present the outputs with tables, visualizations and insights (text).
But what about automating the whole report generation and emailing the final report as an attached document every month at a specific time? In this post I am going to explain how to do it in Windows. If you do a search on google, you will find several threads on stackoverflow and a few good specific posts on it. However it took me sometimes to get it working and had to try different options before. That’s why I am writing this quick tutorial, including screenshots, hoping you might get it your report automated faster!
1. Create your Rmarkdown report
In RStudio create a new Rmarkdown document where you will enter your R code and texts. Mine is called “Schedule_Report.Rmd” and here is what is does:
- retrieve some data from Google Analytics API using the RGoogleAnalytics library
- turn dates into a more friendly format
- create a trend line chart of sessions using the ggplot2 package
A very basic report. Remember that in Rmarkdown you can decide whether to show each chunk of code or not. I showed just the final outputs that are the table and the bar chart.
2. Create an R script that executes and email your Rmarkdown report
Create a new R …read more
Source:: r-bloggers.com