Skip to content

Commit

Permalink
Clarify explanation comments
Browse files Browse the repository at this point in the history
Co-authored-by: Sam Firke <[email protected]>
  • Loading branch information
olivroy and sfirke authored Jun 27, 2024
1 parent cc9edbb commit c77aa0a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/tabyl.R
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ tabyl_3way <- function(dat, var1, var2, var3, show_na = TRUE, show_missing_level
dat <- dplyr::select(dat, !!var1, !!var2, !!var3)
var3_numeric <- is.numeric(dat[[3]])

# Sometimes, attributes can be dropped with transformation.
# Preserve labels, as attributes are sometimes dropped during transformations.
var1_label <- attr(dat[, 1], "label", exact = TRUE)
var2_label <- attr(dat[, 2], "label", exact = TRUE)

Expand Down Expand Up @@ -289,7 +289,7 @@ tabyl_3way <- function(dat, var1, var2, var3, show_na = TRUE, show_missing_level
}

result <- split(dat, dat[[rlang::quo_name(var3)]])
# split() drops attributes, so we manually add back the 1st variable attribute.
# split() drops attributes, so we manually add back the label attributes.
result <- lapply(result, function(x) {
attr(x[[1]], "label") <- var1_label
attr(x[[2]], "label") <- var2_label
Expand Down

0 comments on commit c77aa0a

Please sign in to comment.