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

Create a description of the change in a value #11

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

brancengregory
Copy link
Member

No description provided.

@brancengregory brancengregory changed the title Initial draft complete Create a description of the change in a value Sep 12, 2024
@brancengregory
Copy link
Member Author

brancengregory commented Sep 12, 2024

Todo:

  • Cover all combinations of input_unit and output_unit
  • Add tests for more cases
  • Write docs

For consideration:

  • Use input_unit for output when output_unit not supplied

@brancengregory brancengregory self-assigned this Sep 12, 2024
@brancengregory brancengregory added the enhancement New feature or request label Sep 12, 2024
@anthonyokc
Copy link

Thoughts on binary argument which appends "from {before} to {after} {clean_input_unit}" to the change statement or "at {before} {clean_input_unit}" for the unchanged case?

So "increased by 50 percentage points from 25 to 75 percent" for example. Or "remained unchanged at 25 percent".

@brancengregory
Copy link
Member Author

Yeah, I dig it!

@anthonyokc
Copy link

Also argument direction_verbs = c("increased by", "decreased by")? You can swap them out with say direction_verbs = c("rose by", "fell by") if you wanna mix things up and reduce monotony. Simple to implement

@brancengregory
Copy link
Member Author

@anthonyokc, can you explain what the use case for absolute is? I'm now thinking it only matters when include_values = TRUE

@anthonyokc
Copy link

anthonyokc commented Sep 12, 2024

include_values isn't commited so I'm not sure which that is. But I think absolute was just to cover the case of when the change was negative so it said "decreased by 32 percent" instead of "decreased by -32 percent" but you're right in that it doesn't have to be an argument, it can just be hardcoded to cover that case. It came from how I was doing it adhoc originally. It's like a vestigial organ lol

@brancengregory
Copy link
Member Author

brancengregory commented Sep 12, 2024

Gotchu, I think my implementation will cover that. What do you think of this function signature:

describe_change <- function(
  before,
  after,
  input_unit,
  output_unit,
  absolute = TRUE,
  template = "{direction} {change} {unit}",
  phrasing = list(
    increase = "increased by",
    decrease = "decreased by",
    none = "remained unchanged"
  ),
  include_values = FALSE
)

where include_values is the appending

@brancengregory
Copy link
Member Author

I could use change_phrase as the argument rather than phrasing maybe?

@anthonyokc
Copy link

anthonyokc commented Sep 12, 2024

I would either use phrases and change direction in template to phrase as well or use direction_phrases just to make the relation between the two explicit.

Also just curious is there a reason to use list instead of named character vector?

@brancengregory
Copy link
Member Author

brancengregory commented Sep 12, 2024

Also just curious is there a reason to use list instead of named character vector?

Easier to access in the code with $ vs ["item_name"], and also for tibble and purrr friendliness

I actually did it as a named vector first and didn't like it. Thoughts?

@brancengregory
Copy link
Member Author

Actually I'm backtracking that. Named vector makes sense since all the values are strings

@brancengregory brancengregory marked this pull request as ready for review September 13, 2024 03:16
@brancengregory
Copy link
Member Author

I think I have enough tests and edge cases covered for an initial version

@brancengregory
Copy link
Member Author

This would be a minor version bump

@brancengregory
Copy link
Member Author

brancengregory commented Sep 13, 2024

  • Add unit to the numbers in the appended og values for clarity
  • Probably should only allow arg include_values to be true if the user doesn't pass a custom template. If they do, make them handle that themself
  • Add tests for include_values and above exclusive argument functionality
  • Pass the template function through cli::pluralize so the user can do that themself if they want
  • Document the variables it is possible to include in template

@brancengregory brancengregory marked this pull request as draft September 13, 2024 03:28
@brancengregory
Copy link
Member Author

@anthonyokc the edge cases keep flowing lol, but hoping to knock these last couple checkboxes and open for review tomorrow

@anthonyokc
Copy link

lol this is incredible. This is far beyond what I expected from a 1.0 version of this haha. We should definitely commit to these being the last tasks for now though lol. Cover vast majority of use cases.

@brancengregory brancengregory marked this pull request as ready for review September 28, 2024 23:55
@brancengregory
Copy link
Member Author

@anthonyokc I completed all the outstanding tasks and this is ready to go

@brancengregory
Copy link
Member Author

@anthonyokc Vignette complete!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add function, change, which creates text statements about changes between two data points.
2 participants