- Notifications
You must be signed in to change notification settings - Fork27
This is the companion repository for the lightning talk given December 2020 to the R Finance group
lindblb/pro_reports_talk
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is the companion repository for the lightning talk given___________________
Getting rmarkdown to work correctly is always a struggle for me, thereare a lot of moving parts. Don’t be discouraged if you can’t get thisrepo working immediately. Keep debugging and send me a message if youget stuck.
The renv package was used to create and maintain the environment forthis project. First install this package if you haven’t already
remotes::install_github("rstudio/renv")
When you open the project associated with this repo (after installingrenv), it should activate the renv. Check this with
renv::status()
Next, install the dependencies needed to run this code with
renv::restore()
This project was created on Win10, with R version 4.0.2. If you installthis on Linux or Mac, you may have an issue with the fonts used onR/rmarkdown/report_master.Rmd. The mainfont in the yaml header needs tobe changed to a font you have installed. Ubuntu is a font option forUbuntu-based distros. I used Calibri on my win10 machine.
On Ubuntu, you will more than likely have to install the magick++package with anapt command, the output from renv::restore() shouldtell you what you need to do.
The goal here is to create parameterized (param’d) reports for afinancial institution that has three branches. We want to:
- Read financial data from a SQL database
- Create various tables and charts in an rmarkdown document
- Knit the document to a pdf that can be distributed to whomever
You can run the reports from the terminal with
Rscript R/main.R
or you can run main.R from the R repl. This should place three pdfs inthe/finished_reports/ folder.
Rmarkdown will knit our PDF packets and KableExtra will help us formatour financial tables. Renv will help us maintain our environment andglue will be very helpful in parameterizing our reports and strings.
Thedata-raw/fake.R script creates fake financialdata for us with thecharlatanR package. Then it writes a few tables to a local SQLite db. We willping this database in our example, but you could obviously connect toany data with this method.
Our main rmarkdown document is what I’ll call a “parent”, with severalchildren rmarkdown files.R/rmarkdown/report_master.Rmd knitstogether various children rmarkdown docs located inR/rmarkdown.
We rely on thekableExtrapackage heavily at this stage. A good tutorial for using kableExtra withpdf output can be foundhere.
The last step is to iterate over the three branches in our example, andcreate a report for each, given the parameter: branch.
R/main.R is the file that runs our actual process. First itsources ourR/setup.R file and then constructs a functionto knit a pdf for each branch given thebranch parameter.
If you runR/main.R, at this point you should have threepdfs infinished_reports.
Reach out to me at bradley.lindblad[at]gmail.com or my websitetechnistema.com.
About
This is the companion repository for the lightning talk given December 2020 to the R Finance group
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
