Skip to content

Commit

Permalink
feat(register_beancount()): Now import 'id' column
Browse files Browse the repository at this point in the history
* ``register_beancount()`` now imports a transaction `id` column (#21).
  Thanks @vikasrawal for suggestion.

closes #21
  • Loading branch information
trevorld committed May 17, 2024
1 parent 4b23ea2 commit ee475bb
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 34 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rakefile
CONTRIBUTING
examples.rst
LICENSE.md
README.html
README.Rrst
README.rst
Expand Down
8 changes: 5 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
Package: ledger
Type: Package
Title: Utilities for Importing Data from Plain Text Accounting Files
Version: 2.0.9
Authors@R: c(person("Trevor L", "Davis", role = c("aut", "cre"), email="[email protected]"),
Version: 2.0.10-0
Authors@R: c(person("Trevor L.", "Davis", role=c("aut", "cre"),
email="[email protected]",
comment = c(ORCID = "0000-0001-6341-4639")),
person("Jenya", "Sovetkin", role="ctb"),
person("Chris", "Lloyd", role="ctb"))
URL: https://github.com/trevorld/r-ledger, https://trevorldavis.com/R/ledger/
Expand All @@ -21,5 +23,5 @@ Suggests:
testthat
SystemRequirements: ledger (>= 3.1), hledger (>= 1.2), beancount (>= 2.0)
License: MIT + file LICENSE
RoxygenNote: 7.1.2
RoxygenNote: 7.3.1
Encoding: UTF-8
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
YEAR: 2017-2018
YEAR: 2024
COPYRIGHT HOLDER: Trevor L. Davis
25 changes: 25 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
The MIT License (MIT)
=====================

Copyright © 2024 Trevor L. Davis

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the “Software”), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.
34 changes: 20 additions & 14 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
ledger 2.0.10 (development)
===========================

* ``register_beancount()`` now imports a transaction `id` column (#21).
Thanks @vikasrawal for suggestion.

ledger 2.0.9
============

* The R packgae `{rio}` has been downgraded from "Imports" to "Suggests".
* The R package `{rio}` has been downgraded from "Imports" to "Suggests".
Users who want to use `rio::import()` or `rio::convert()`
will need to manually install `{rio}`.

Expand All @@ -21,23 +27,23 @@ ledger 2.0.6
ledger 2.0.4
============

* For ``beancount`` files read in with ``register_beancount`` with the end ``date`` argument set
* For ``beancount`` files read in with ``register_beancount()`` with the end ``date`` argument set
we no longer use any price directives on the end date to determine market value
but only those strictly before the end date.
This matches the filtering of transactions and the new ``hledger`` market value behavior.

ledger 2.0.2
============

* For ``ledger`` files ``register`` no longer filters out transactions with amount equal to zero (#13).
* For ``ledger`` files ``register()`` no longer filters out transactions with amount equal to zero (#13).

ledger 2.0.0
============

Breaking changes
----------------

* Now ``register`` returns a ``tibble`` instead of a ``data.frame``.
* Now ``register()`` returns a ``tibble`` instead of a ``data.frame``.
* By default now reads in ``beancount`` files using the output from ``bean-query``
instead of ``bean-report`` followed up by ``hledger``.
* Most users of the ``ledger`` R package won't need to change any code.
Expand All @@ -46,15 +52,15 @@ New functions
-------------

* Now has ``prune_coa`` and ``prune_coa_string`` functions to help simplify plaintext accounting "Chart of Accounts" names to a given maximum depth.
* Lower level ``register_beancount``, ``register_ledger``, and ``register_hledger`` functions are now exported (and documented).
* Lower level ``register_beancount()``, ``register_ledger()``, and ``register_hledger()`` functions are now exported (and documented).

Minor improvements and fixes
----------------------------

* ``register`` now has a ``date`` argument than can be used to exclude transactions
* ``register()`` now has a ``date`` argument than can be used to exclude transactions
(and implicitly price statements) before that date.
* ``register`` now preserves transaction comments when importing ledger files (#16). Thanks Jenya Sovetkin for patch.
* ``register`` now preserves tags when importing beancount files.
* ``register()`` now preserves transaction comments when importing ledger files (#16). Thanks Jenya Sovetkin for patch.
* ``register()`` now preserves tags when importing beancount files.

ledger 1.0.1
============
Expand All @@ -64,7 +70,7 @@ ledger 1.0.1
ledger 0.8.0
============

* Implemented a workaround to get ``register`` working with ``ledger `` and ``bean-report`` on Windows (#15).
* Implemented a workaround to get ``register()`` working with ``ledger `` and ``bean-report`` on Windows (#15).

ledger 0.7.0
============
Expand All @@ -74,20 +80,20 @@ ledger 0.7.0
ledger 0.6.0
============

* Add ``toolchain`` argument to ``register`` and ``net_worth``.
* Add ``toolchain`` argument to ``register()`` and ``net_worth()``.
* Add new columns to ``net_worth``.

ledger 0.5.3
============

* Removed ``include_cleared``, ``include_pending``, ``include_unmarked``, ``convert_to_cost``, and ``convert_to_market_value`` arguments from ``register`` (#6).
* Added ``flags`` arguments to ``register`` (#6).
* Removed ``include_cleared``, ``include_pending``, ``include_unmarked``, ``convert_to_cost``, and ``convert_to_market_value`` arguments from ``register()`` (#6).
* Added ``flags`` arguments to ``register()`` (#6).
* Added a new ``mark`` column to imported data frames with values ``"*"``, ``"!"``, or ``""`` (#6).
* For hledger/beancount files added new ``historical_cost``, ``hc_commodity``, ``market_value`` and ``mv_commodity`` columns (#6).
* Wrote and exported S3 methods so can use ``rio::import`` to read in registers (#7).
* Wrote and exported S3 methods so can use ``rio::import()`` to read in registers (#7).
* Now throws an error if required binaries not found (#8).
* Fixed bug in importing hledger or beancount files (now automatically casts ``amount`` field to numeric).
* Added new ``net_worth`` function.
* Added new ``net_worth()`` function.



33 changes: 18 additions & 15 deletions R/register.r
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ register <- function(file, ..., toolchain = default_toolchain(file), date = NULL
tidyselect::matches("market_value"),
tidyselect::matches("mv_commodity"),
tidyselect::matches("comment"),
tidyselect::matches("tags"))
tidyselect::matches("tags"),
tidyselect::matches("id"))
}

.nf <- function(filename) shQuote(normalizePath(filename, mustWork = FALSE))
Expand Down Expand Up @@ -133,7 +134,7 @@ register_beancount <- function(file, date = NULL) {
"number as amount, currency as commodity,",
"number(cost(position)) as historical_cost,",
"currency(cost(position)) as hc_commodity,",
"tags,")
"tags, id,")
if (!is.null(date)) {
date <- as.Date(date)
query <- paste(query,
Expand All @@ -156,17 +157,18 @@ register_beancount <- function(file, date = NULL) {
df <- .read_csv(cfile)
if (nrow(df) == 0) {
df <- tibble(date = as.Date(character()),
mark = character(),
account = character(),
payee = character(),
description = character(),
amount = numeric(),
commodity = character(),
historical_cost = numeric(),
hc_commodity = character(),
market_value = numeric(),
mv_commodity = character(),
tags = character())
mark = character(),
account = character(),
payee = character(),
description = character(),
amount = numeric(),
commodity = character(),
historical_cost = numeric(),
hc_commodity = character(),
market_value = numeric(),
mv_commodity = character(),
tags = character(),
id = character())
}
df <- mutate(df,
mark = str_trim(.data$mark),
Expand All @@ -176,7 +178,8 @@ register_beancount <- function(file, date = NULL) {
commodity = str_trim(.data$commodity),
hc_commodity = str_trim(.data$hc_commodity),
mv_commodity = str_trim(.data$mv_commodity),
tags = str_squish(.data$tags))
tags = str_squish(.data$tags),
id = str_trim(.data$id))
.select_columns(df)
}

Expand Down Expand Up @@ -204,7 +207,7 @@ register_hledger <- function(file, flags = "", date = NULL, add_mark = TRUE, add

.register_hledger_helper <- function(hfile, flags = "", add_mark = TRUE) {
df <- .read_hledger(hfile, flags)
if (!add_mark) df <- select(df, -.data$mark)
if (!add_mark) df <- select(df, -"mark")
df
}

Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
destination: "/home/trevorld/a/projects/websites/R/ledger/"
destination: "../../websites/R/ledger/"
url: "https://trevorldavis.com/R/ledger"
development:
mode: auto

0 comments on commit ee475bb

Please sign in to comment.