Skip to content

Commit

Permalink
Create print.one_skim_df, document reassign_skim_attrs and modify rec…
Browse files Browse the repository at this point in the history
…oncile_skimrs in response to changes in 4.2 and R CMD CHK issues.
  • Loading branch information
elinw committed Apr 26, 2022
1 parent 5251639 commit 562b753
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ S3method(knit_print,skim_df)
S3method(knit_print,skim_list)
S3method(knit_print,summary_skim_df)
S3method(mutate,skim_df)
S3method(print,one_skim_df)
S3method(print,skim_df)
S3method(print,skim_list)
S3method(print,summary_skim_df)
Expand Down
2 changes: 1 addition & 1 deletion R/reshape.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ reconcile_skimmers <- function(data, groups, base) {
))
matched_cols <- dplyr::intersect(all_columns, with_base_columns)
extra_cols <- dplyr::setdiff(all_columns, with_base_columns)
if (length(extra_cols) > 0) {
if (length(extra_cols) > 0 && "skim_type" %in% names(data)) {
grouped <- dplyr::group_by(data, .data$skim_type)
complete_by_type <- dplyr::summarize_at(
grouped,
Expand Down
7 changes: 5 additions & 2 deletions R/skim_obj.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,12 @@ strip_skim_attrs <- function(object) {
attributes(object) <- stripped
object
}

#' @param object a skim object
#' @param skim_df name of new skim object
#' @param ... additional options
#'
#' Pass attributes from a `skimr` object to a new object.
#' @noRd
#' @keywords internal
reassign_skim_attrs <- function(object, skim_df, ...) {
defaults <- list(
class = c("skim_df", "tbl_df", "tbl", "data.frame"),
Expand Down
21 changes: 21 additions & 0 deletions R/skim_print.R
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,27 @@ print.skim_df <- function(x,
}
}

#' @export
print.one_skim_df <- function(x,
include_summary = TRUE,
n = Inf,
width = Inf,
summary_rule_width = getOption(
"skimr_summary_rule_width",
default = 40
),
...) {
if (is_skim_df(x) && nrow(x) > 0) {
if (include_summary) {
print(summary(x), .summary_rule_width = summary_rule_width, ...)
}

print(x, width = width, n = n, ...)
} else {
NextMethod("print")
}
}


# Methods for correctly formatting a a `one_skim_df`. We leverage the
# customiztion options in `pillar` for this. It divides the results into: a
Expand Down

0 comments on commit 562b753

Please sign in to comment.