Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions R/desc.R
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ process_summaries.desc_layer <- function(x, ...) {
# Transpose the summaries that make up the first number in a display string
# into the the `value` column with labels by `stat`
pivot_longer(cols = match_exact(trans_vars), names_to = "stat") %>%
rowwise() %>%
# Add in the row labels
# Add in the row labels (vectorized lookup instead of rowwise)
mutate(
row_label = row_labels[[stat]]
row_label = unname(row_labels[stat])
)

# If precision is required, then create the variable identifier
Expand Down
14 changes: 5 additions & 9 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -224,17 +224,13 @@ apply_row_masks <- function(dat, row_breaks=FALSE, ...) {
# Get the row labels that need to be masked
nlist <- names(dat)[str_detect(names(dat), "row_label")]

# Iterate each variable
# Iterate each variable and blank out consecutive repeats
for (name in nlist){
dat <- dat %>%
# Identify if the value was repeating (ugly compensation for first row)
mutate(mask = ifelse(!(is.na(lag(!!sym(name)))) & !!sym(name) == lag(!!sym(name)), TRUE, FALSE),
# If repeating then blank out
!!name := ifelse(mask == TRUE, '', !!sym(name))
)
vals <- dat[[name]]
lagged <- c(NA, vals[-length(vals)])
is_repeat <- !is.na(lagged) & vals == lagged
dat[[name]] <- ifelse(is_repeat, '', vals)
}
# Drop the dummied mask variable
dat <- dat %>% select(-mask)

dat
}
Expand Down