Skip to content

Commit

Permalink
add percent check back in zone_summary
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Carvalho committed Apr 23, 2024
1 parent 4d1b306 commit 1023c23
Showing 1 changed file with 61 additions and 61 deletions.
122 changes: 61 additions & 61 deletions R/zone_summary.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,67 +142,67 @@ zone_summary <- function(dat,
zone_tab <- agg_helper(dataset, value = var, group = c(zone.dat, group),
fun = fun, count = count)

# # percent flag
# if (!is.null(fun) && fun == "percent"){
# calc_perc <- TRUE
# } else {
# calc_perc <- FALSE
# }
#
# if (count) {
#
# if (!calc_perc & is.null(group)) {
# # count zones
# val_var <- "n"
# legend_name <- "# of obs"
#
# } else if (calc_perc & is.null(group)) {
# # count zones, then perc
# val_var <- "perc"
# val_2 <- "n"
# legend_name <- "% of total obs"
#
# } else if (calc_perc & !is.null(group)) {
# # count group by zone, then perc (one plot per group)
# val_var <- "perc"
# val_2 <- "n"
# multi_plot <- TRUE
#
# } else if (!calc_perc & !is.null(group)) {
# # count group by zone (one plot per group)
# val_var <- "n"
# multi_plot <- TRUE
#
# } else stop("Invalid arguments.", call. = FALSE)
#
# } else {
#
# if (!calc_perc & is.null(var)) {
#
# stop("Invalid arguments. Set 'count = TRUE' or include a numeric variable",
# " to aggregate by.", call. = FALSE)
#
# } else if (calc_perc & is.null(var)) {
#
# stop("Invalid arguments. Include a numeric variable to aggregate by.",
# call. = FALSE)
#
# } else if (!calc_perc & !is.null(var)) {
# # agg var by zone
# legend_name <- paste0(var, " (", fun, ")")
# val_var <- var
#
# } else if (calc_perc & !is.null(var)) {
# # agg var by zone, then perc
# val_var <- paste0(var,"_perc")
# val_2 <- var
# legend_name <- paste("% of total", var)
#
# } else stop("Invalid arguments.", call. = FALSE)
#
# if (!is.null(group)) multi_plot <- TRUE
# }
#
# percent flag
if (!is.null(fun) && fun == "percent"){
calc_perc <- TRUE
} else {
calc_perc <- FALSE
}

if (count) {

if (!calc_perc & is.null(group)) {
# count zones
val_var <- "n"
legend_name <- "# of obs"

} else if (calc_perc & is.null(group)) {
# count zones, then perc
val_var <- "perc"
val_2 <- "n"
legend_name <- "% of total obs"

} else if (calc_perc & !is.null(group)) {
# count group by zone, then perc (one plot per group)
val_var <- "perc"
val_2 <- "n"
multi_plot <- TRUE

} else if (!calc_perc & !is.null(group)) {
# count group by zone (one plot per group)
val_var <- "n"
multi_plot <- TRUE

} else stop("Invalid arguments.", call. = FALSE)

} else {

if (!calc_perc & is.null(var)) {

stop("Invalid arguments. Set 'count = TRUE' or include a numeric variable",
" to aggregate by.", call. = FALSE)

} else if (calc_perc & is.null(var)) {

stop("Invalid arguments. Include a numeric variable to aggregate by.",
call. = FALSE)

} else if (!calc_perc & !is.null(var)) {
# agg var by zone
legend_name <- paste0(var, " (", fun, ")")
val_var <- var

} else if (calc_perc & !is.null(var)) {
# agg var by zone, then perc
val_var <- paste0(var,"_perc")
val_2 <- var
legend_name <- paste("% of total", var)

} else stop("Invalid arguments.", call. = FALSE)

if (!is.null(group)) multi_plot <- TRUE
}

# # confid check ----
# # skip check if rule = "k" and count = TRUE
# cc_par <- get_confid_check(project)
Expand Down

0 comments on commit 1023c23

Please sign in to comment.