diff --git a/R/hts_summary.R b/R/hts_summary.R index 0830d7c..656d47f 100644 --- a/R/hts_summary.R +++ b/R/hts_summary.R @@ -21,7 +21,16 @@ #' @param checkbox_yesval Value of checkbox_valname that indicates it was selected. #' Default is NULL. Must be provided if summarize_var is a checkbox variable. #' -#' @return A data.table containing +#' @return A list containing (if applicable) categorical and numeric summaries of the +#' specified variable(s), as well as sample sizes and whether or not the summarized +#' variable is a shared checkbox variable. +#' To access the categorical/numeric df use output$summary. +#' To access the weighted df use output$summary$wtd, and output$summary$unwtd for the +#' unweighted df. +#' To access the weight name use output$summary$weight_name. +#' To access sample sizes use output$n_ls. +#' To access weighted and unweighted sample sizes respectively, use output$n_ls$wtd +#' and output$n_ls$unwtd. #' @export #' #' @examples @@ -38,11 +47,11 @@ #' 'day' = day, #' 'trip' = trip, #' 'vehicle' = vehicle))$cat -#' hts_summary(prepped_dt = DT, -#' summarize_var = 'age', -#' summarize_by = 'employment', -#' summarize_vartype = 'categorical', -#' wtname = 'person_weight') +#' output = hts_summary(prepped_dt = DT, +#' summarize_var = 'age', +#' summarize_by = 'employment', +#' summarize_vartype = 'categorical', +#' wtname = 'person_weight') #' #' DT = hts_prep_data(summarize_var = 'speed_mph', #' summarize_by = 'age', @@ -52,11 +61,13 @@ #' 'day' = day, #' 'trip' = trip, #' 'vehicle' = vehicle))$num -#' hts_summary(prepped_dt = DT, -#' summarize_var = 'speed_mph', -#' summarize_by = 'age', -#' summarize_vartype = 'numeric', -#' wtname = 'trip_weight') +#' output = hts_summary(prepped_dt = DT, +#' summarize_var = 'speed_mph', +#' summarize_by = 'age', +#' summarize_vartype = 'numeric', +#' wtname = 'trip_weight') +#' + hts_summary = function( prepped_dt, diff --git a/R/hts_summary_num.R b/R/hts_summary_num.R index 44249fa..43f1a4f 100644 --- a/R/hts_summary_num.R +++ b/R/hts_summary_num.R @@ -126,6 +126,12 @@ hts_summary_num = function(prepped_dt, } + if (weighted){ + + num_summary_ls$weight_name = wtname + + } + return(num_summary_ls) } diff --git a/man/hts_summary.Rd b/man/hts_summary.Rd index d6951dc..295d6e4 100644 --- a/man/hts_summary.Rd +++ b/man/hts_summary.Rd @@ -49,7 +49,16 @@ Must be provided if summarize_var is a checkbox variable.} Default is NULL. Must be provided if summarize_var is a checkbox variable.} } \value{ -A data.table containing +A list containing (if applicable) categorical and numeric summaries of the +specified variable(s), as well as sample sizes and whether or not the summarized +variable is a shared checkbox variable. +To access the categorical/numeric df use output$summary. +To access the weighted df use output$summary$wtd, and output$summary$unwtd for the +unweighted df. +To access the weight name use output$summary$weight_name. +To access sample sizes use output$n_ls. +To access weighted and unweighted sample sizes respectively, use output$n_ls$wtd +and output$n_ls$unwtd. } \description{ Make household travel survey summaries @@ -68,11 +77,11 @@ DT = hts_prep_data(summarize_var = 'age', 'day' = day, 'trip' = trip, 'vehicle' = vehicle))$cat -hts_summary(prepped_dt = DT, - summarize_var = 'age', - summarize_by = 'employment', - summarize_vartype = 'categorical', - wtname = 'person_weight') +output = hts_summary(prepped_dt = DT, + summarize_var = 'age', + summarize_by = 'employment', + summarize_vartype = 'categorical', + wtname = 'person_weight') DT = hts_prep_data(summarize_var = 'speed_mph', summarize_by = 'age', @@ -82,9 +91,10 @@ DT = hts_prep_data(summarize_var = 'speed_mph', 'day' = day, 'trip' = trip, 'vehicle' = vehicle))$num -hts_summary(prepped_dt = DT, - summarize_var = 'speed_mph', - summarize_by = 'age', - summarize_vartype = 'numeric', - wtname = 'trip_weight') +output = hts_summary(prepped_dt = DT, + summarize_var = 'speed_mph', + summarize_by = 'age', + summarize_vartype = 'numeric', + wtname = 'trip_weight') + }