On Tue, Jan 28, 2014 at 12:47 PM, Rémi Vanicat <[email protected]> wrote:
> I had the time, I would have export the RAW numbers to R for analysis.
FWIW, here is what I use for this:
library(stringr)
library(lubridate)
getPostings <- function(day=NULL, unit="month",
account="Aufwand:Einkauf:Lebensmittel:?") {
account <- str_c("^", str_replace_all(account, " ", "\\\\s"))
opts <- if (length(day) == 2) {
paste( "--begin"
, strftime(day[1], "%Y/%m/%d")
, "--end"
, strftime(day[2], "%Y/%m/%d")
)
} else if (!is.null(day)) {
paste( "--begin"
, strftime(floor_date(day, unit), "%Y/%m/%d")
, "--end"
, strftime(ceiling_date(day, unit), "%Y/%m/%d")
)
} else {
""
}
p <- pipe(paste("ledger csv", opts, account))
ledger <- read.csv(p, header=FALSE, stringsAsFactors=FALSE, flush=TRUE,
col.names=c("date", "code", "payee", "account",
"commodity", "amount", "status", "note"))
ledger$date <- strptime(ledger$date, "%Y/%m/%d")
ledger$payee <- factor(ledger$payee)
ledger$commodity <- factor(ledger$commodity)
ledger$status <- factor(ledger$status, c("", "*"))
levels(ledger$payee) <- c(levels(ledger$payee), "Other")
ledger$account <- factor(str_replace(ledger$account, account, ""))
levels(ledger$account) <- c(levels(ledger$account), "Other")
return(ledger)
}
test <- getPostings(c(ymd("2012/09/01"), ymd("2013/03/01")))
--
---
You received this message because you are subscribed to the Google Groups
"Ledger" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.