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

bring add_totals functions up to v1.0 as add_totals #99

Merged
merged 30 commits into from
Mar 30, 2017

Conversation

sfirke
Copy link
Owner

@sfirke sfirke commented Mar 22, 2017

Closes #57, lots of discussion there.

@sfirke sfirke requested a review from rgknight March 22, 2017 02:50
@codecov
Copy link

codecov bot commented Mar 22, 2017

Codecov Report

Merging #99 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff          @@
##           master    #99   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          14     14           
  Lines         310    325   +15     
=====================================
+ Hits          310    325   +15
Impacted Files Coverage Δ
R/adorn_helpers.R 100% <ø> (ø) ⬆️
R/ns_to_percents.R 100% <100%> (ø) ⬆️
R/adorn_crosstab.R 100% <100%> (ø) ⬆️
R/add_totals.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0bcf091...6fd5cf7. Read the comment docs.

@sfirke
Copy link
Owner Author

sfirke commented Mar 22, 2017

hmph I see I need to add a little test coverage. Will do that. I brought this up to 100% test coverage. @rgknight would you be up for reviewing the code in this PR? If you don't have time, I feel good about merging this in to master as-is.

Copy link
Collaborator

@rgknight rgknight left a comment

Choose a reason for hiding this comment

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

Looks good! Great stuff. Some of the code feels heavy but we are not aiming for lightweight here so I think that's fine. Overall I think I prefer an adorn_ approach to things that modify a tabyl, but have shared that before and support whichever approach you decide to take.

R/add_totals.R Outdated

if("col" %in% which){
# Add totals col
clean_dat <- clean_names(dat) # bad names will make select_if choke
Copy link
Collaborator

Choose a reason for hiding this comment

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

Reference the relevant dplyr issue here; this should be temporary

Copy link
Owner Author

Choose a reason for hiding this comment

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

Done.

dat
}

### Deprecated functions -----------------------------
#' @title Append a totals row to a data.frame.
#'
#' @description
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the help reference that it is deprecated?

Copy link
Owner Author

@sfirke sfirke Mar 28, 2017

Choose a reason for hiding this comment

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

Yep, good call. I'll add that.

  • Deprecate the retired add_totals_* functions in their documentation

@@ -18,32 +19,32 @@
#' # when total_n is needed
#' mtcars %>%
#' crosstab(am, cyl) %>%
#' add_totals_row() %>% # add a totals row that should not be included in the denominator
#' add_totals("row") %>% # add a totals row that should not be included in the denominator
#' ns_to_percents(denom = "all", total_n = nrow(mtcars)) # specify correct denominator

ns_to_percents <- function(dat, denom = "row", na.rm = TRUE, total_n = NULL){
Copy link
Collaborator

Choose a reason for hiding this comment

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

One option for a v1.0 approach:

This is a function primarily intended to modify a tabyl, so it would be an adorn function, probably adorn_percent(denom="row") for the percent of total over rows.

If you included both adorn_N and adorn_percent in the pipe after a tabyl, it would behave like adorn_crosstab does now, or maybe just add columns for both if that's easier.

It sounds hard to make tably create an environment that could allow for multiple adorn_ functions to be stacked. I think it's possible, but I have no idea how to do it.

R/add_totals.R Outdated
#' add_totals()


add_totals <- function(dat, which = c("row", "col"), fill = "-", na.rm = TRUE){
Copy link
Collaborator

Choose a reason for hiding this comment

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

I prefer adorn_totals as this is something that is primarily intended to modify a tabyl. I think that adorn_crosstab may eventually become the outlier in the adorn_ approach. I think I've given this feedback already, though, so I assume that you have heard it and decided on verb_object approach to things that modify a tabyl.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I think there's something to this, and I agree that adorn_crosstab will become the outlier (a) because the nomenclature of "crosstab" may go away and (b) if we can fully replicate its functionality with modular pieces like this. In that case, I do like the common prefix of adorn_ and could see this as adorn_totals.

I want to merge this in now rather than wait for us to figure out #101, since this closes existing bugs. I'm not sure if it should be add_totals when we might later re-route people to adorn_totals... maybe adorn_totals now. I think this won't be set in stone until we resolve #101, the big question, and so no matter what we call it now, the name and behavior of the totals function could ultimately change. Say, if the totals function needs to add an attribute to a tabyl to convey info to ns_to_percents down the line.

Copy link
Owner Author

Choose a reason for hiding this comment

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

okay, I renamed it adorn_totals.

@sfirke sfirke merged commit 085fb4f into master Mar 30, 2017
@sfirke sfirke deleted the improve_adorn_helpers branch March 30, 2017 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants