Skip to content

Commit

Permalink
Merge pull request #166 from szimmer/print-summary-width
Browse files Browse the repository at this point in the history
Improve printing for survey objects to respect width
  • Loading branch information
gergness authored Oct 16, 2023
2 parents 5542105 + e26862e commit 74e47ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 11 additions & 8 deletions R/survey_vars.r
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,17 @@ print.survey_vars <- function(x, all = FALSE, ...) {
cat("Sampling variables:\n")
lapply(seq_along(x), function(y) {
if (!is.null(x[[y]])) {
if (length(x[[y]]) > 7 & !all) {
num_vars <- length(x[[y]])
print_vars <- x[[y]][1:5]
cat(paste0(" - ", names(x[y]), ": ", paste(print_vars, collapse = ", "),
", ... (", num_vars - 5, " more)\n"))
} else {
cat(paste0(" - ", names(x[y]), ": ", paste(x[[y]], collapse = ", "),
"\n"))
if (!is.null(x[[y]])) {
fixcarriage <- function(x){
# remove carriage return in repweights and extra space
out <- gsub("\\n ", "", x)
if (is.symbol(x)){
as.symbol(out)
} else{
out
}
}
cat(wrap(paste0(" - ", names(x[y]), ": ", paste(lapply(x[[y]], fixcarriage), collapse=", ")), indent=2), "\n")
}
}
})
Expand Down
7 changes: 4 additions & 3 deletions R/tbl-svy.r
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ print.tbl_svy <- function (x, varnames = TRUE, all_survey_vars = FALSE, ...) {
print(survey_vars(x), all_survey_vars)
}
if(length(groups(x)) != 0) {
cat("Grouping variables: ")
cat(paste0(deparse_all(groups(x)), collapse = ", "))
cat("Grouping variables: \n")
cat(wrap(paste0("- ", deparse_all(groups(x)), collapse = ", "), indent=2))
cat("\n")
}

Expand All @@ -63,7 +63,8 @@ print.tbl_svy <- function (x, varnames = TRUE, all_survey_vars = FALSE, ...) {
}

var_types <- paste0(vars, " (", types, ")", collapse = ", ")
cat(wrap("Data variables: ", var_types), "\n", sep = "")
cat("Data variables: \n")
cat(wrap(" - ", var_types, indent = 2), "\n", sep = "")
invisible(x)
}
}
Expand Down

0 comments on commit 74e47ef

Please sign in to comment.