knitr::opts_chunk$set(collapse = TRUE, comment = "#>") library(homeBudget)
To start your home budget use the function read_csvCreditCard()
to load your credit card statement into R. The statements must be csv text documents which can be downloaded from your online bank account. For example, if you have saved your most recent JP Morgan Chase statement in the directory /home/user/budget
as myChaseStatement.csv
you would load it using the following:
read_csvCreditCard(file = "/home/user/budget/myChaseStatement.csv", Date = "Posting Date", Amount = "Amount", Description = "Description", company = "Chase")
The argument company
indicates the company responsible for the credit card and determines how to load the csv data so there is a consistent structure. Presently the following companies are supported:
r toString(shQuote(eval(formals(read_csvCreditCard)$company)))
Please contact the maintainer to request additional companies.
Rather than loading every csv every session we can save the data in a single file using the function saveCreditCard()
.
saveCreditCard(path = "/home/user/budget", creditCardHistory)
This saves a file entitled creditCardHistory.rda
onto your computer at the location specified in path
. Be sure that your previous home budget data has been properly loaded
and appended before saving as the contents will be overwritten with the new file (see below).
In subsequent sessions you can load the saved history of your credit card transactions creditCardHistory.rda
from the location that it was previously saved.
loadCreditCard(path = "/home/user/budget")
Access to your csv data may be limited to recent statements. For a comprehensive budget we will want to keep an ongoing history of all transactions by appending new csv statements onto the saved history creditCardHistory.rda
.
Here's a typical scenario, you want to add recent statements from multiple credit cards to your home budget.
myOldData <- loadCreditCard(path = "/home/user/budget") myNewData <- read_csvCreditCard(file = "/home/user/budget/myNewChaseStatement.csv", company = "Chase") someAmExData <- read_csvCreditCard(file = "/home/user/budget/AmEx_20020601.csv", company = "American Express") allData <- appendCreditCardData(myOldData, myNewData, someAmExData) saveCreditCard(path = "/home/user/budget", creditCardHistory = allData)
We load the prior data stored on your computer in the file creditCardHistory.rda
into our current R session and name the table myOldData
. Then we read in a new csv credit card statement named myNewChaseStatement.csv
and call this myNewData
. Similarly, there is new American Express data named AmEx_20020601.csv
that is read into a table we will call someAmExData
. To combine the new and old datasets we use appendCreditCardData()
to get a complete history which we name allData
. We save the complete history back to our computer, overwriting creditCardHistory.rda
, for future use.
The budget categories are defined in a list of named character vectors. Each category contains a string of patterns to match the description in the credit card statement. This can either be a substring of the longer description or include regex operators, as detailed within ICU regular expressions. The package includes a list of category patterns for a typical budget and is documented in ?categoryPatternsExample
.
The Description
is the text provided by the credit card company describing the purchase.
Description <- c('rent 2019 march', 'Happy Co. gas 20190601', 'New fancy restaurant')
A simple budget category could look like:
myCategories <- list(housing = c('rent', 'Hardware Inc'), transportation = 'gas')
We convert descriptions of credit card transaction into discrete categories using addCategories
.
addCategories(Description = Description, myCategories)
The description 'rent 2019 march'
has been assigned to housing
because the substring 'rent'
is part of that budget category. Notice that 'New fancy restaurant'
is categorized as MISSING
because none of the patterns in any of the budget categories match it. We can create a new budget category entertainment
.
myCategories <- list(housing = c('rent', 'Hardware Inc'), transportation = 'gas', entertainment = "restaurant") addCategories(Description = Description, myCategories)
A work by Rafael Kuttner
r.i.kuttner@gmail.com
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.