Family of seven related functions to analyze transactions data frames that have credit, debit, and tetrapartite (lsd) or tetrapartite (lsdf) columns, mimicking an account book.
deb_account()
credit, debit, and current value of a single account.deb_account_summary()
credit, debit, and current value of all accounts.deb_credit()
total credit of each account.deb_debit()
total debit of each account.deb_current()
current value of each account (credit - debit).deb_open()
current value of each account that has a positive or negative value.deb_balance()
positive and negative value remaining in a transactions data frame.
Usage
deb_account(
df,
account_id,
credit = credit,
debit = debit,
lsd = lsd,
na.rm = FALSE
)
deb_account_summary(
df,
credit = credit,
debit = debit,
lsd = lsd,
na.rm = FALSE
)
deb_credit(df, credit = credit, debit = debit, lsd = lsd, na.rm = FALSE)
deb_debit(df, credit = credit, debit = debit, lsd = lsd, na.rm = FALSE)
deb_current(df, credit = credit, debit = debit, lsd = lsd, na.rm = FALSE)
deb_open(df, credit = credit, debit = debit, lsd = lsd, na.rm = FALSE)
deb_balance(df, credit = credit, debit = debit, lsd = lsd, na.rm = FALSE)
Arguments
- df
A data frame or tibble with at least credit, debit, and lsd columns.
- account_id
The id of the account to be used to calculate the credit, debit, and current values.
- credit
Credit column: Unquoted name of the credit column, representing the accounts that discharge the transactional values or from which the values derive. Default is
credit
.- debit
Debit column: Unquoted name of the debit column, representing the accounts that receive the transactional values. Default is
debit
.- lsd
Value column: Unquoted name of a column of class
deb_lsd
,deb_decimal
, ordeb_tetra
. Default islsd
.- na.rm
Logical. Should missing values (including
NaN
) be removed?
Value
Transaction functions return a data frame or tibble with columns for the
accounts in df
and credit, debit, and/or current values in the same type
and bases
as lsd
:
deb_account()
: a data frame with three rows showing the credit, debit, and current value of the given account.deb_account_summary()
a data frame with one row for each account indf
and credit, debit, and current value columns.deb_credit()
: a data frame with one row for each account with the total credit of the accounts.deb_debit()
: a data frame with one row for each account with the total debit of the accounts.deb_current()
: a data frame with one row for each account with the current value of the accounts.deb_open()
: a data frame with one row for each account whose current value is not0
. If all accounts are equal to zero, a data frame with zero rows will be returned.deb_balance()
: a data frame with two rows showing the credit and debit remaining indf
.
Transactions data frames:
Transactions data frames have the structure of an account book. They
should have a similar arrangement to dafforne_transactions
. Each row is
a transaction in the book. credit
and debit
columns contain the
account ids associated with discharging account (credit) and the receiving
account (debit). The lsd
column represents the tripartite or
tetrapartite value of each transaction. Like dafforne_transactions
,
transactions data frames can have additional columns with attributes for
each transaction such as id or date among others.
Examples
# Examples use dafforne_transactions data,
# which have default column names.
# See dafforne_accounts for account names.
# Credit, debit, and current value of cash account
deb_account(dafforne_transactions, account_id = 1,
credit = credit, debit = debit,
lsd = lsd)
#> # A tibble: 3 × 2
#> relation lsd
#> <chr> <lsd[20s:12d]>
#> 1 credit 1956:10s:11d
#> 2 debit 2903:13s:0d
#> 3 current -947:-2s:-1d
# Credit, debit, and current value of profit and loss account
deb_account(dafforne_transactions, account_id = 23)
#> # A tibble: 3 × 2
#> relation lsd
#> <chr> <lsd[20s:12d]>
#> 1 credit 1075:8s:11d
#> 2 debit 29:0s:1d
#> 3 current 1046:8s:10d
# Summary of all accounts in Dafforne's ledger
deb_account_summary(dafforne_transactions)
#> # A tibble: 46 × 4
#> account_id credit debit current
#> <dbl> <lsd[20s:12d]> <lsd[20s:12d]> <lsd[20s:12d]>
#> 1 1 1956:10s:11d 2903:13s:0d -947:-2s:-1d
#> 2 2 2006:3s:9d 150:0s:0d 1856:3s:9d
#> 3 3 570:0s:0d 570:0s:0d 0:0s:0d
#> 4 4 75:0s:8d 75:0s:8d 0:0s:0d
#> 5 5 813:3s:0d 813:3s:0d 0:0s:0d
#> 6 6 568:1s:11d 869:2s:7d -301:0s:-8d
#> 7 7 2958:18s:10d 2958:18s:10d 0:0s:0d
#> 8 8 1580:10s:0d 1580:10s:0d 0:0s:0d
#> 9 9 1744:1s:4d 1744:1s:4d 0:0s:0d
#> 10 10 606:2s:6d 606:2s:6d 0:0s:0d
#> # ℹ 36 more rows
# Credit of accounts in Dafforne's ledger
deb_credit(dafforne_transactions)
#> # A tibble: 46 × 2
#> account_id lsd
#> <dbl> <lsd[20s:12d]>
#> 1 1 1956:10s:11d
#> 2 2 2006:3s:9d
#> 3 3 570:0s:0d
#> 4 4 75:0s:8d
#> 5 5 813:3s:0d
#> 6 6 568:1s:11d
#> 7 7 2958:18s:10d
#> 8 8 1580:10s:0d
#> 9 9 1744:1s:4d
#> 10 10 606:2s:6d
#> # ℹ 36 more rows
# Debit of accounts in Dafforne's ledger
deb_debit(dafforne_transactions)
#> # A tibble: 46 × 2
#> account_id lsd
#> <dbl> <lsd[20s:12d]>
#> 1 1 2903:13s:0d
#> 2 2 150:0s:0d
#> 3 3 570:0s:0d
#> 4 4 75:0s:8d
#> 5 5 813:3s:0d
#> 6 6 869:2s:7d
#> 7 7 2958:18s:10d
#> 8 8 1580:10s:0d
#> 9 9 1744:1s:4d
#> 10 10 606:2s:6d
#> # ℹ 36 more rows
# Current value of accounts in Dafforne's ledger
current <- deb_current(dafforne_transactions)
current
#> # A tibble: 46 × 2
#> account_id lsd
#> <dbl> <lsd[20s:12d]>
#> 1 1 -947:-2s:-1d
#> 2 2 1856:3s:9d
#> 3 3 0:0s:0d
#> 4 4 0:0s:0d
#> 5 5 0:0s:0d
#> 6 6 -301:0s:-8d
#> 7 7 0:0s:0d
#> 8 8 0:0s:0d
#> 9 9 0:0s:0d
#> 10 10 0:0s:0d
#> # ℹ 36 more rows
# Current value of open account in Dafforne's ledger
open <- deb_open(dafforne_transactions)
open
#> # A tibble: 14 × 2
#> account_id lsd
#> <dbl> <lsd[20s:12d]>
#> 1 1 -947:-2s:-1d
#> 2 2 1856:3s:9d
#> 3 6 -301:0s:-8d
#> 4 14 512:3s:8d
#> 5 19 991:7s:6d
#> 6 20 -1092:-17s:-10d
#> 7 23 1046:8s:10d
#> 8 33 99:7s:7d
#> 9 35 -189:-12s:0d
#> 10 37 -446:-12s:-9d
#> 11 39 -402:-12s:-1d
#> 12 43 -413:-6s:-8d
#> 13 45 -806:-6s:-11d
#> 14 46 93:19s:8d
# Compare the amount of rows in returned values of
# deb_current() vs deb_open()
nrow(current)
#> [1] 46
nrow(open)
#> [1] 14
# Credit and debit remaining on Dafforne's ledger
deb_balance(dafforne_transactions)
#> # A tibble: 2 × 2
#> relation lsd
#> <chr> <lsd[20s:12d]>
#> 1 credit 4599:11s:0d
#> 2 debit -4599:-11s:0d