--- title: "Untitled" author: "Matt" date: "April 7, 2016" output: html_document --- ```{r setup, include=FALSE} knitr::opts_chunk$set(echo = TRUE) ``` ```{r} # Use https://github.com/maxconway/gsheet library(gsheet) # Use the functions in ledgerr (the package that is part of this project) but don't load the package itself--this will let us deploy to Shiny.io more easily. library(R.utils) #for sourceDirectory() sourceDirectory("ledgerr/R") # Pull Google sheet locations from another file (journal1, journal2, etc.) source("config.R") # Combine bank accounts journal<-rbind(journal1,journal2) ## Clean up # Date is date journal$Date<-as.Date(journal$Date,format="%m/%d/%Y") # Replace empty classes and accounrs journal$Class[journal$Class==""]<-c("unclassified") journal$Account[journal$Account==""]<-c("unclassified") # Class, Accounts are factors journal$Class<-as.factor(journal$Class) journal$Account<-as.factor(journal$Account) # Empty class should be NA # Debit and Credit are numeric, without commas journal$Debit<-as.numeric(sub(",","",journal$Debit)) journal$Credit<-as.numeric(sub(",","",journal$Credit)) # See other reports in QB and Ledger ################# work in progress ## This could replace net.acc, check numbers a<-aggregate(cbind(Credit,Debit=-Debit)~Account,data=journal,function(x) sum(x, na.rm=TRUE),na.action="na.pass") # Select by class (modify to include dates) #a<-aggregate(cbind(Credit,Debit=-Debit)~Account,data=journal[journal$Class %in% "Bikecicle",],function(x) sum(x, na.rm=TRUE),na.action="na.pass") # na.pass: http://stackoverflow.com/a/16844940/2152245 # This is a column rename on the fly: "Debit=-Debit" # Calculate net column a$Net<-rowSums(a[,2:3],na.rm=T) # Calculate total--need to clean up colSums(a[-1]) # This could replace net.class, check numbers a<-aggregate(cbind(Credit,Debit=-Debit)~Class,data=journal,function(x) sum(x, na.rm=TRUE),na.action="na.pass") # Calculate net column a$Net<-rowSums(a[,2:3],na.rm=T) # Calculate total--need to clean up colSums(a[-1]) ``` ```{r deploy} # See Shiny documentation for authorizing computer to deploy to shiny.io. # For Shiny library(rsconnect) # Deploy deployApp() ```