Closed StefanBRas closed 4 years ago
I'd accept a pull request if it doesn't break hledger import for earlier versions of hledger that this package currently support. An ideal target would be whichever version of hledger introduced the --unmarked
flag which I currently use (seems to be after hledger 1.2 which is the version that comes with Ubuntu 18.04 LTS).
I'm not sure how painless switching to hledger print
will be. I'm seeing with the package's built-in example in inst/extdata/example.hledger
for some rows I get amount column like 4 @ 250 USD
and commodity SP
with hledger print
whereas hledger register
gives me a much more consistent to parse 4 SP
. It seems between hledger 1.2 and hledger 1.15.2 the amount column for those rows with the print command with the -V
flag (which we also use) went from 2000.00 @ 250 USD
to just 2000.00
.
In those cases it seems though you'd just need to detect and discard those @ blah
values that only appear sometimes. So maybe it isn't that hard.
I think adding decimal separator support might be possible within R using regular expressions and gsub
. Write an to_numeric
function that does:
.
or ,
to a ;
.
and ,
;
to .
as.numeric
Development version should now have decimal separator support for hledger via a more robust to_numeric
function. Still no support for commodity prefixes.
Ah, i didn't think to check with earlier versions.
My idea with using "commodity 100.00 \
But doing the trick with adding "commodity ..." to the bottom of my own .journal file solves both the problems for me, and i probably won't get around to make a pull request.
Thanks for the quick replies
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 beNA
. 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.
Reproducible code
Note that this will create a file called "temp.journal" in the current directory)
Solutions
Commodity placement
Using
hledge print -o file.csv
instead ofhledge register -o file.csv
yields a file with all the information from usingregister
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)
The columns are named in the same way, so it wouldn't change much.
Decimal separator
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 likehledger print -o file.csv
to find all commodities in use, like abovehledger register
exactly as in the original implementation. I have tried it with a single commodity and it worked.