# WARNING - Generated by {fusen} from dev/flat_utils.Rmd: do not edit by hand

#' Frequencies and proportions in one output
#'
#' Combines base::table() and base::prop.table() outputs in a single one
#'
#' @param ... Arguments passed to \code{base::table()}.
#' @param margin Integer 1L. The same argument as in base::prop.table()
#' @param round Integer 1L. Number of digits after decimal in base::prop.table() output
#' @param noquote Logical 1L. If TRUE, return an object of class noquote that provides better view of the output
#' @return Matrix or noquote matrix. Frequencies with proportions in brackets, within a matrix
#' @examples
#' df <- data.frame(
#'                  "variable_1" = c("v1_1", "v1_1",
#'                                   "v1_2", "v1_2", "v1_2", "v1_2"),
#'                  "variable_2" = c("v2_1", "v2_1", "v2_1", "v2_1",
#'                                   "v2_2", "v2_2")
#'                                   )
#' table_prop(df$variable_1)
#' table_prop(df$variable_1, df$variable_2)
#' table_prop(df$variable_1, df$variable_2, margin = 2, noquote = TRUE)
#' df <- data.frame("person_id" = c(1, 1, 2, 3,
#'                                  2, 4, 5, 5 ,1),
#'                  "person_age" = c(25, 25, 21, 32,
#'                                   21, 48, 50, 50, 52),
#'                  "survey_month" = c("jan", "feb", "mar", "apr",
#'                                     "apr", "may", "jun", "jul", "jan"),
#'                  "survey_answer" = c("no", "yes", "no", "yes",
#'                                      "yes", "yes", "no", "yes", NA))
#'
#' table_prop(df$survey_month)
#' table_prop(df$survey_month, df$survey_answer)
#' table_prop(df$survey_month, df$survey_answer, 
#'            margin = 2, round = 4)
#' @export
#'
table_prop <- function (..., margin = NULL, round = 3, noquote = FALSE) {
  
  table <- table(...)
  ptable <- round(prop.table(table, margin), round)
  
  result <- matrix(paste0(table, " (", ptable, ")"), nrow = nrow(table))
  dimnames(result) <- dimnames(table)
  
  
  if (noquote) noquote(result) else result
}
