trevorld / r-ledger Goto Github PK
View Code? Open in Web Editor NEWImports data from plain text accounting files
License: Other
Imports data from plain text accounting files
License: Other
add_historical_cost
should be TRUE
and for add_market_value
should be file_ext(file) != "ledger"
.hc_commodity
and mv_commodity
columns.select(-)
to select final columns.Currently use either bean-report (h)ledger
and then either ledger csv
or hledger register -o csv
. Right now bean-query "SELECT *"
doesn't give me what I want/need (in particular missing the crucial account field plus parsing historical cost and/or market values look like could be a bit of a pain as well):
$ bean-example > example.bean
$ bean-query -f csv example.bean "SELECT *" | csvlook | head
|-------------+------+---------------------------+--------------------------------------------------+---------------------------------|
| date | flag | payee | narration | position |
|-------------+------+---------------------------+--------------------------------------------------+---------------------------------|
| 2016-01-01 | * | | Opening Balance for checking account | 3762.36 USD |
| 2016-01-01 | * | | Opening Balance for checking account | -3762.36 USD |
| 2016-01-01 | * | | Allowed contributions for one year | -18000 IRAUSD |
| 2016-01-01 | * | | Allowed contributions for one year | 18000 IRAUSD |
| 2016-01-03 | * | RiverBank Properties | Paying the rent | -2400.00 USD |
| 2016-01-03 | * | RiverBank Properties | Paying the rent | 2400.00 USD |
| 2016-01-04 | * | BANK FEES | Monthly bank fee | -4.00 USD |
Add mark
, cost
, cost_commodity
, value
, value_commodity
columns to imported data frame. Do this by importing in the register several times with a helper function and then merge/join them. Also add an end date option to the helper function to aid with net worth at various times calculations.
simonmichael/hledger#810 (comment)
By comparison when using ledger zero amount transactions are stripped completely...
Seems to be an upstream "bug" in ledger csv
.
By comparison when using hledger to import zero amount transactions have missing commodity
Seem to have installed fine and should be cross-platform...
Hi
As the title states, register_hledge
fails if the currency is formatted with a comma as the decimal separator and/or the commodity is prefixed. It will import the transactions, but all amounts will be NA
. All of these formats are the official format somewhere.
I found possible solutions (see below) such that the user doesn't need to change his original hledger files and where the internals of register_hledge
stays roughly the same, with a few additions.
I have not yet implemented the solutions, but if you agree with them i can make a pull request.
Either way, it took me some time to find error so i believe a more descriptive error message would be good.
Note that this will create a file called "temp.journal" in the current directory)
> writeLines(c("2016/01/01 Rent", " assets 100.00 EUR"," expenses"), "temp.journal")
> register_hledger("temp.journal") # works
# A tibble: 2 x 11
date mark payee description account amount commodity historical_cost
<date> <chr> <lgl> <chr> <chr> <dbl> <chr> <dbl>
1 2016-01-01 "" NA Rent assets 100 EUR 100
2 2016-01-01 "" NA Rent expens… -100 EUR -100
...
> writeLines(c("2016/01/01 Rent", " assets 100,00 EUR"," expenses"), "temp.journal")
> register_hledger("temp.journal") # will import NAs
# A tibble: 2 x 11
date mark payee description account amount commodity historical_cost
<date> <chr> <lgl> <chr> <chr> <dbl> <chr> <dbl>
1 2016-01-01 "" NA Rent assets NA EUR NA
2 2016-01-01 "" NA Rent expens… NA EUR NA
# … with 3 more variables: hc_commodity <chr>, market_value <dbl>,
# mv_commodity <chr>
Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
3: NAs introduced by coercion
> writeLines(c("2016/01/01 Rent", " assets EUR 100.00"," expenses"), "temp.journal")
> register_hledger("temp.journal") # Will import NAs
# A tibble: 2 x 11
date mark payee description account amount commodity historical_cost
<date> <chr> <lgl> <chr> <chr> <dbl> <chr> <dbl>
1 2016-01-01 "" NA Rent assets NA 100.00 NA
2 2016-01-01 "" NA Rent expens… NA -100.00 NA
# … with 3 more variables: hc_commodity <chr>, market_value <dbl>,
# mv_commodity <chr>
Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
3: NAs introduced by coercion
> writeLines(c("2016/01/01 Rent", " assets EUR 100,00"," expenses"), "temp.journal")
> register_hledger("temp.journal") "will imports NAs"
# A tibble: 2 x 11
date mark payee description account amount commodity historical_cost
<date> <chr> <lgl> <chr> <chr> <dbl> <chr> <dbl>
1 2016-01-01 "" NA Rent assets NA 100,00 NA
2 2016-01-01 "" NA Rent expens… NA -100,00 NA
# … with 3 more variables: hc_commodity <chr>, market_value <dbl>,
# mv_commodity <chr>
Warning messages:
1: NAs introduced by coercion
2: NAs introduced by coercion
3: NAs introduced by coercion
Using hledge print -o file.csv
instead of hledge register -o file.csv
yields a file with all the information from using register
but where the amount is split into an "amount" and "commodity" field. Hence the commodity could be extracted from that column.
For example: (using the same temp.journal from above)
$ hledger register -f temp.journal -o tempReg.csv
$ hledger print -f temp.journal -o tempPrint.csv
$ cat tempReg.csv
"txnidx","date","code","description","account","amount","total"
"1","2016/01/01","","Rent","assets","EUR 100,00","EUR 100,00"
"1","2016/01/01","","Rent","expenses","EUR -100,00","0"
$ cat tempPrint.csv
"txnidx","date","date2","status","code","description","comment","account","amount","commodity","credit","debit","posting-status","posting-comment"
"1","2016/01/01","","","","Rent","","assets","100,00","EUR","","100,00","",""
"1","2016/01/01","","","","Rent","","expenses","-100,00","EUR","100,00","","",""
The columns are named in the same way, so it wouldn't change much.
This solution is a bit more "hacky" but I believe it's pretty robust.
hledger allows one to specify commodity directives with commodity 100.00 USD
- but it has to be a part of the journal file. So a possible solution could work like
hledger print -o file.csv
to find all commodities in use, like abovehledger register
exactly as in the original implementation.Write .import_beancount
, .import_bean
, .import_ledger
, and .import_hledger
that simply calls ledgeR::register
on the file. Check with rio maintainers if should be contributed there.
This is due to a bug in bean-report
https://bitbucket.org/blais/beancount/issues/199/bean-report-hledger-ledger-puts-link-tag
Due to a non-reversible-change in behaviour introduced in hledger v1.15.
Pre v1.15 behaviour -V --end=DATE
is now equivalent to v1.15 behaviour --end=DATE --value=now
whereas we need v1.15 behaviour --end=DATE --value=end
Refine unit tests for beancount to check for both bean-report and other engines
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.