Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

address breaking change in dplyr::last() #491

Merged
merged 1 commit into from
Oct 21, 2022
Merged
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
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

## Bug fixes

* `adorn_percentages()` was refactored for compatibility with `dplyr` package versions > 1.0.99 (#490)

* When a numeric variable is supplied as the 2nd variable (column) or 3rd variable (list) of a `tabyl`, the resulting columns or list are now sorted in numeric order, not alphabetic. (#438, thanks **@daaronr** for reporting and **@mattroumaya** for fixing)

* `tabyl()` now succeeds when the second variable is named `"n"` (#445).
Expand Down
4 changes: 2 additions & 2 deletions R/adorn_percentages.R
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ adorn_percentages <- function(dat, denominator = "row", na.rm = TRUE, ...) {
if ("col" %in% attr(dat, "totals") & !explicitly_exempt_totals) {
cols_to_tally <- c(cols_to_tally, ncol(dat))
if ("row" %in% attr(dat, "totals")) {
col_sum <- c(col_sum, sum(dplyr::last(dat)[-nrow(dat)]))
col_sum <- c(col_sum, sum(dat[-nrow(dat), ncol(dat)]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just FYI, another way to extract the last column with dplyr is dplyr::pull(dat).

} else {
col_sum <- c(col_sum, sum(dplyr::last(dat)))
col_sum <- c(col_sum, sum(dat[ , ncol(dat)]))
}
}
dat[cols_to_tally] <- sweep(dat[cols_to_tally], 2, col_sum, `/`) # from http://stackoverflow.com/questions/9447801/dividing-columns-by-colsums-in-r
Expand Down