Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

This is the companion repository for the lightning talk given December 2020 to the R Finance group

NotificationsYou must be signed in to change notification settings

lindblb/pro_reports_talk

Repository files navigation

hero

About

This is the companion repository for the lightning talk given___________________

Installation

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.

{renv}

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()

OS Issues

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.

Tutorial

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.

Key packages

key players

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.

Get financial data from SQL

flowchart

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.

Create rmarkdown

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.

Knit to pdf(s)

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.

Contact

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp