This project contains an R script designed specifically for analysing Danske Bank statement exports. The script loads the Excel worksheet provided by the bank, categorises spending using simple regular expressions, and then creates summary charts for monthly spending trends and average expenses per category.
Install the packages in R with:
install.packages(c("plyr", "ggplot2", "readxl"))-
Download your Danske Bank transactions as an Excel file (the default name resembles
DanskeKonto-<account>-<date>.xlsx) and place it in the project directory. -
Open
StatementAnalyzerDanskeBank.Rand replace the hard-coded Excel filename in theread_excel()call with the name of your export file. -
Ensure the worksheet structure matches the script expectations: the columns should be (in order) Date, Text, Amount, Balance, and any additional metadata provided by the bank. If your export differs, adjust the
col_typesargument passed toread_excel()accordingly. -
From an R session (or RStudio), source the script:
source("StatementAnalyzerDanskeBank.R")The script filters out income rows, assigns spending categories, and generates two plots:
- Monthly totals per category: a faceted scatter and smoothing chart of spending over time.
- Average monthly expense per category: a bar chart summarising typical outgoings.
-
Use R's plotting window to inspect or save the generated charts.
The categorisation logic uses regular expressions stored in variables such as cash, food, flights, transport, gas, and rent. Update the regex patterns or add new variables to reflect your own merchants and spending categories, then extend the nested ifelse block to map them to friendly labels.
For more flexible categorisation, consider extracting the mapping into a lookup table (e.g. a CSV file) and applying it with dplyr::case_when() or a join. This keeps the logic declarative and easier to maintain.
- Add unit tests or sample data to make it easier to verify changes.
- Parameterise the input file path so the script can be run from the command line without editing the source.
- Replace the nested
ifelsestatements with a tidier approach such asdplyr::case_when(). - Export the visualisations directly to image files (e.g. via
ggsave) for sharing or reporting. - Package the script as an R function or minimal package to improve reusability.
This project currently has no explicit license. Consider adding one to clarify usage rights.