Title: | Utilities for Importing Data from Plain Text Accounting Files |
---|---|
Description: | Utilities for querying plain text accounting files from 'Ledger', 'HLedger', and 'Beancount'. |
Authors: | Trevor L. Davis [aut, cre] , Jenya Sovetkin [ctb], Chris Lloyd [ctb] |
Maintainer: | Trevor L. Davis <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2.0.11-0 |
Built: | 2024-11-16 04:50:29 UTC |
Source: | https://github.com/trevorld/r-ledger |
default_toolchain
determines default tool chain used for reading in register.
default_toolchain(file)
default_toolchain(file)
file |
Filename for a ledger, hledger, or beancount file. |
Computes net worth for a vector of dates. Computes net worth at the beginning of the day before any transactions have occurred.
net_worth( file, date = Sys.Date() + 1, include = c("^asset", "^liabilit", "^<revalued>"), exclude = NULL, flags = "-V", toolchain = default_toolchain(file), ignore_case = TRUE )
net_worth( file, date = Sys.Date() + 1, include = c("^asset", "^liabilit", "^<revalued>"), exclude = NULL, flags = "-V", toolchain = default_toolchain(file), ignore_case = TRUE )
file |
Filename for a ledger, hledger, or beancount file. |
date |
Vector of dates to compute net worth for. For each only the transactions (and price statements) before that date are used in the net worth calculation. |
include |
Character vector of regular expressions of accounts to include in the net worth calculation.
Use |
exclude |
Character vector of regular expressions of accounts to exclude from the net worth calculation.
Use |
flags |
Extra flags to pass to |
toolchain |
Toolchain used to read in register. Either "ledger", "hledger", "bean-report_ledger", or "bean-report_hledger". |
ignore_case |
logical value of whether to ignore case in regular expressions or not. |
net_worth
returns a tibble
## Not run: example_beancount_file <- system.file("extdata", "example.beancount", package = "ledger") net_worth(example_beancount_file) net_worth(example_beancount_file, c("2016-01-01", "2017-01-01", "2018-01-01")) ## End(Not run)
## Not run: example_beancount_file <- system.file("extdata", "example.beancount", package = "ledger") net_worth(example_beancount_file) net_worth(example_beancount_file, c("2016-01-01", "2017-01-01", "2018-01-01")) ## End(Not run)
prune_coa
is a convenience function that modifies a data frame
by either editing in place or making
a new variable containing the plaintext "Chart of Accounts" pruned to a given maximum depth
e.g. "Assets:Checking:Credit-Union:Account1" at a maximum depth of 2 will be converted to "Assets:Checking".
prune_coa
uses tidyverse non-standard evaluation (NSE).
prune_coa_string
is a convenience function which does the pruning operation on character vectors.
prune_coa(df, depth = 1, variable, name) prune_coa_string(x, depth = 1)
prune_coa(df, depth = 1, variable, name) prune_coa_string(x, depth = 1)
df |
A data frame |
depth |
How deep should the account structure be. |
variable |
Which variable to make less deep (default is to use "account") |
name |
New variable name (default is to edit the variable argument in place) |
x |
Character vector |
df <- tibble::tribble(~account, ~amount, "Assets:Checking:BankA", 1000, "Assets:Checking:BankB", 1000, "Assets:Savings:BankA", 1000, "Assets:Savings:BankC", 1000) prune_coa(df) prune_coa(df, 2) prune_coa(df, 3) prune_coa(df, 4) prune_coa(df, 2, account, account2) prune_coa(prune_coa(df, 2, account, account2), 3, account2, account3) prune_coa_string(df$account, 2)
df <- tibble::tribble(~account, ~amount, "Assets:Checking:BankA", 1000, "Assets:Checking:BankB", 1000, "Assets:Savings:BankA", 1000, "Assets:Savings:BankC", 1000) prune_coa(df) prune_coa(df, 2) prune_coa(df, 3) prune_coa(df, 4) prune_coa(df, 2, account, account2) prune_coa(prune_coa(df, 2, account, account2), 3, account2, account3) prune_coa_string(df$account, 2)
register
imports the register from a ledger, hledger, or beancount file as a tibble.
register(file, ..., toolchain = default_toolchain(file), date = NULL) register_beancount(file, date = NULL) register_hledger( file, flags = "", date = NULL, add_mark = TRUE, add_cost = TRUE, add_value = TRUE ) register_ledger(file, flags = "", date = NULL)
register(file, ..., toolchain = default_toolchain(file), date = NULL) register_beancount(file, date = NULL) register_hledger( file, flags = "", date = NULL, add_mark = TRUE, add_cost = TRUE, add_value = TRUE ) register_ledger(file, flags = "", date = NULL)
file |
Filename for a ledger, hledger, or beancount file. |
... |
Arguments passed on to either |
toolchain |
Toolchain used to read in register. Either "ledger", "hledger", "beancount", "bean-report_ledger", or "bean-report_hledger". |
date |
End date. Only transactions (and implicitly price statements) strictly before this date are used. |
flags |
Character vector of additional command line flags to pass
to either |
add_mark |
Whether to add a column with the mark information. Only relevant for hledger files. |
add_cost |
Whether to add historical cost columns. Only relevant for hledger files. |
add_value |
Whether to add market value columns. Only relevant for hledger files. |
register
returns a tibble.
if (Sys.which("ledger") != "") { example_ledger_file <- system.file("extdata", "example.ledger", package = "ledger") dfl <- register(example_ledger_file) head(dfl) } if (Sys.which("hledger") != "") { example_hledger_file <- system.file("extdata", "example.hledger", package = "ledger") dfh <- register(example_hledger_file) head(dfh) } if (Sys.which("bean-query") != "") { example_beancount_file <- system.file("extdata", "example.beancount", package = "ledger") dfb <- register(example_beancount_file) head(dfb) }
if (Sys.which("ledger") != "") { example_ledger_file <- system.file("extdata", "example.ledger", package = "ledger") dfl <- register(example_ledger_file) head(dfl) } if (Sys.which("hledger") != "") { example_hledger_file <- system.file("extdata", "example.hledger", package = "ledger") dfh <- register(example_hledger_file) head(dfh) } if (Sys.which("bean-query") != "") { example_beancount_file <- system.file("extdata", "example.beancount", package = "ledger") dfb <- register(example_beancount_file) head(dfb) }