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

format_tags_diff() #404

Open
seth127 opened this issue Sep 24, 2021 · 5 comments · May be fixed by #498
Open

format_tags_diff() #404

seth127 opened this issue Sep 24, 2021 · 5 comments · May be fixed by #498
Assignees
Labels
tags related to managing tags in bbr
Milestone

Comments

@seth127
Copy link
Collaborator

seth127 commented Sep 24, 2021

Makes a nicely formatted column for HTML log_df tables that shows the tags added and removed

Discussion Points

  • this is fairly specific to HTML formatting. We should test with pdf and other rendering stuff and see if we need to change anything, or maybe make an argument like format = c("html", "pdf") or something.
  • We should also test how this interacts with knitr::kable()

Proposed Code

format_tags_diff <- function(.log_df, .keep = FALSE) {
  if (
    !any(str_detect(names(.log_df), "tags_added")) ||
    !any(str_detect(names(.log_df), "tags_removed"))
  ) {
    stop("Must have both `tags_added` and `tags_removed` columns to call `format_tags_diff()`. Use `add_tags_diff()` to create them")
  }
  .log_df <- bbr::suppressSpecificWarning(
    collapse_to_string(.log_df, tags_added, tags_removed),
    .regexpr = "collapse_to_string\\(\\) only works on list columns"
  ) %>%
    mutate(
      tags_diff = paste0(tags_added, "; ~~", tags_removed, "~~") %>% 
        str_replace("; ~~~~","") %>% 
        str_replace("^; ", "")
    )
  if (isFALSE(.keep)) {
    .log_df <- select(.log_df, -tags_added, -tags_removed)
  }
  return(.log_df)
}
@seth127 seth127 added this to the New NONMEM helper functions milestone Sep 24, 2021
@seth127 seth127 added the tags related to managing tags in bbr label Sep 24, 2021
@barrettk
Copy link
Collaborator

barrettk commented Jun 3, 2022

@seth im not sure this function is right unless im missing something (I know its WIP). Im finding that tags_added and tags_removed are not necessarily names of tags_diff(log_df), but rather one level down:

> tags_diff(log_df)
$`1`
$`1`$tags_added
[1] "acop tag"  "other tag"

$`1`$tags_removed
[1] ""


$`2`
$`2`$tags_added
[1] "new tag 1" "new tag 2"

$`2`$tags_removed
[1] "acop tag"  "other tag"


$`3`
$`3`$tags_added
[1] "the newest"

$`3`$tags_removed
[1] "other tag" "new tag 2"

Perhaps .log_df should be renamed to .tags_diff or something? (was originally trying to pipe in log_df, which wont have those column names)

Im going to write the stories/requirements assuming my assumption is correct. Wanted to give it a run before writing them to have a better understanding of functionality, but I can definitely put something together for whats here right now

@barrettk
Copy link
Collaborator

barrettk commented Jun 3, 2022

Stories:

MGMT-S013 (this already exists):
  name: format tags difference
  description: As a user, I want to be able to see the difference in the tags element
    of different models. Be able to either compare two models directly, or compare
    all models in a `bbi_run_log_df` to their "parent models" (i.e. the models in
    that same tibble that match their `based_on`).
  ProductRisk: Medium
  Requirements:
     - (requirements of previous tests)
     - MGMT-R011
     - MGMT-R012

New Requirements:

MGMT-R011:
  description: format_tags_diff() should turn the output of `tags_diff(log_df)` into a nicely formatted html or PDF table
  tests: 
MGMT-R012:
  description: format_tags_diff() should create a `tags_diff` column for each model and optionally allow `tags_added` and `tags_removed` to remain in the output
  tests: 

@barrettk barrettk self-assigned this Jun 13, 2022
@seth127
Copy link
Collaborator Author

seth127 commented Jun 13, 2022

This is sort of right but the issue that you're looking at the output of tags_diff() and this will actually be from add_tags_diff(). See the "Value" section of these docs for the distinction.

As discussed offline, this might be better as a .format argument to add_tags_diff(). Proposed behavior:

  • Defaults to NULL, causing the returned tibble to have tags_added and tags_removed (current behavior)
  • Can pass add_tags_diff(..., .format = "html") which would cause the returned tibble to have only tags_diff column added to it, which would be formatted so that it renders as HTML (when someone passes this to knitr::kable() or whatever)
  • Theoretically .format could take other things like "pdf" if we someday want to implement that.

@barrettk you'll have to change the requirements above to match this ^.

@barrettk
Copy link
Collaborator

barrettk commented Jun 13, 2022

@seth127 Im a bit unclear as to what the regex replacements are supposed to be doing. I get the following:
image

Should the removed tags be strikethrough?

EDIT: we have to replace ~~ with <s>/</s>

@barrettk
Copy link
Collaborator

barrettk commented Jun 16, 2022

New Requirement:

TDF-R005:
  description: add_tags_diff() can optionally append a new column with html formatting
  tests:
  - BBR-TDF-005
  - BBR-TDF-006

Added to story:

MGMT-S013:
  name: Tags diff
  description: As a user, I want to be able to see the difference in the tags element
    of different models. Be able to either compare two models directly, or compare
    all models in a `bbi_run_log_df` to their "parent models" (i.e. the models in
    that same tibble that match their `based_on`).
  ProductRisk: Low
  requirements:
  - TDF-R001 (previous)
  - TDF-R002 (previous)
  - TDF-R003 (previous)
  - TDF-R004 (previous)
  - TDF-R005 (new)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tags related to managing tags in bbr
Projects
None yet
2 participants