R/uber_ebit.R

#' Make an income statement upto EBIT for Uber income and expense data
#'
#' This function takes a dataframe of uber income data and user generated
#'   expsenses and combines them to make an income statement up to EBIT.
#'   The statement can be either quarterly or annual (10k or 10q).
#' @param income_data dataframe of income generated by fmt_inc()
#' @param expense_data dataframe of expenses generated by fmt_exp()
#' @param tenQ should the table be quarterly or annual ? Default to annual
#' @param tex if TRUE, prints a latex formatted table as well.
#' @keywords uber accounting EBIT
#' @import magrittr
#' @import dplyr
#' @import plyr
#' @import lubridate
#' @export
#' @examples
#' uber_ebit( myinc.df, myexp.df, tenQ = TRUE, tex = FALSE)

uber_ebit <- function( income_data, expense_data, tenQ = FALSE, tex = FALSE ) {

  # add something to check that the dfs are of the right dims

  # make the annual income statement
  if (tenQ == FALSE) {

    names( income_data )[2] <- "value"
    names( expense_data )[2] <- "value"

    inc <- income_data %>% filter( item == "INCOME")
    exp <- expense_data %>% filter( item == "EXPENSES")

    inc_statement <- bind_rows(
      income_data, expense_data,
      data_frame(item = "EBIT", value = inc$value - exp$value ) )
  } else {

    inc <- income_data %>% filter( item == "INCOME")
    exp <- expense_data %>% filter( item == "EXPENSES")

    EBIT_row <- data_frame( item = "EBIT", Q1 = inc$Q1 - exp$Q1,
                            Q2 = inc$Q2 - exp$Q2, Q3 = inc$Q3 - exp$Q3,
                            Q4 = inc$Q4 - exp$Q4 )

    inc_statement <- bind_rows( income_data, expense_data, EBIT_row )
  }

  # need to add part about stargazer and printing a table...

  return( inc_statement )
}
SmarshMELLOW/ubeRpay documentation built on May 29, 2019, 2:33 p.m.