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

Closes #2415 replaced hard coding of expr(USUBJID, STUDYID) or expr(USUBJID) with … #2452

Conversation

ProfessorP-beep
Copy link
Collaborator

@ProfessorP-beep ProfessorP-beep commented May 30, 2024

…!!!get_admiral_option("subject_keys") to allow for flexibility in using the function. There is an error in the bds_exposure.Rmd markdown on line 361, chunk 22 that needs to be fixed.

Thank you for your Pull Request! We have developed this task checklist from the Development Process Guide to help with the final steps of the process. Completing the below tasks helps to ensure our reviewers can maximize their time on your code as well as making sure the admiral codebase remains robust and consistent.

Please check off each taskbox as an acknowledgment that you completed the task or check off that it is not relevant to your Pull Request. This checklist is part of the Github Action workflows and the Pull Request will not be merged into the main branch until you have checked off each task.

  • Place Closes #<insert_issue_number> into the beginning of your Pull Request Title (Use Edit button in top-right if you need to update)
  • Code is formatted according to the tidyverse style guide. Run styler::style_file() to style R and Rmd files
  • Updated relevant unit tests or have written new unit tests, which should consider realistic data scenarios and edge cases, e.g. empty datasets, errors, boundary cases etc. - See Unit Test Guide
  • If you removed/replaced any function and/or function parameters, did you fully follow the deprecation guidance?
  • Review the Cheat Sheet. Make any required updates to it by editing the file inst/cheatsheet/admiral_cheatsheet.pptx and re-upload a PDF version of it to the same folder.
  • Update to all relevant roxygen headers and examples, including keywords and families. Refer to the categorization of functions to tag appropriate keyword/family.
  • Run devtools::document() so all .Rd files in the man folder and the NAMESPACE file in the project root are updated appropriately
  • Address any updates needed for vignettes and/or templates
  • Update NEWS.md under the header # admiral (development version) if the changes pertain to a user-facing function (i.e. it has an @export tag) or documentation aimed at users (rather than developers). A Developer Notes section is available in NEWS.md for tracking developer-facing issues.
  • Build admiral site pkgdown::build_site() and check that all affected examples are displayed correctly and that all new functions occur on the "Reference" page.
  • Address or fix all lintr warnings and errors - lintr::lint_package()
  • Run R CMD check locally and address all errors and warnings - devtools::check()
  • Link the issue in the Development Section on the right hand side.
  • Address all merge conflicts and resolve appropriately
  • Pat yourself on the back for a job well done! Much love to your accomplishment!

…!!!get_admiral_option("subject_keys") to allow for flexibility in using the function. There is an error in the bds_exposure.Rmd markdown on line 361, chunk 22 that needs to be fixed.
@ProfessorP-beep ProfessorP-beep linked an issue May 30, 2024 that may be closed by this pull request
@ProfessorP-beep ProfessorP-beep changed the title replaced hard coding of expr(USUBJID, STUDYID) or expr(USUBJID) with … #2415 replaced hard coding of expr(USUBJID, STUDYID) or expr(USUBJID) with … May 30, 2024
Copy link

github-actions bot commented May 30, 2024

Code Coverage

Package Line Rate Health
admiral 96%
Summary 96% (4883 / 5082)

@bms63
Copy link
Collaborator

bms63 commented May 30, 2024

Looking nice @ProfessorP-beep! Can you just run styler on your code

ProfessorP-beep and others added 4 commits May 30, 2024 14:12
…_option("subject_keys") in .Rmd files and ran each file to check for errors.
…nctions' of https://github.com/pharmaverse/admiral into 2415-general-issue-make-subject-keys-flexible-in-all-functions

Merged pull request with main branch update
@ProfessorP-beep
Copy link
Collaborator Author

I'm still getting the error with pkgdown::build_site(), but everything else, including running the .Rmd checks out. It's running again right now after merging an update.

@bms63
Copy link
Collaborator

bms63 commented May 30, 2024

I'm still getting the error with pkgdown::build_site(), but everything else, including running the .Rmd checks out. It's running again right now after merging an update.

I will see if I can build site on my end

@bms63
Copy link
Collaborator

bms63 commented May 30, 2024

I was able to build website - I will review PR. @manciniedoardo can you also help with review please.

@bms63 bms63 requested a review from manciniedoardo May 30, 2024 19:49
Copy link
Collaborator

@manciniedoardo manciniedoardo left a comment

Choose a reason for hiding this comment

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

Left some comments, thanks @ProfessorP-beep !

@@ -40,7 +40,7 @@ adae <- ae %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = adsl_vars,
by = exprs(STUDYID, USUBJID)
by = exprs(!!!get_admiral_option("subject_keys"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should be by_vars not by. Partial matching might save us here but better to use the right argument directly.

Also, I believe in this case you could do by_vars = get_admiral_option("subject_keys") directly rather than quoting and unquoting by_vars = exprs(!!!get_admiral_option("subject_keys")) (this is applicable in lots of other places as well.) You'd only need to use exprs and unquoting when you want to use other by vars as well, for instance by_vars = exprs(!!!get_admiral_option("subject_keys"), AEDECOD) - @bundfussr do you agree?

Maybe you could do a blanket find and replace for by_vars = exprs(!!!get_admiral_option("subject_keys")) -> by_vars = get_admiral_option("subject_keys")

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I believe in this case you could do by_vars = get_admiral_option("subject_keys") directly rather than quoting and unquoting by_vars = exprs(!!!get_admiral_option("subject_keys")) (this is applicable in lots of other places as well.) You'd only need to use exprs and unquoting when you want to use other by vars as well, for instance by_vars = exprs(!!!get_admiral_option("subject_keys"), AEDECOD) - @bundfussr do you agree?

I agree.

@@ -36,7 +36,7 @@ adcm <- cm %>%
derive_vars_merged(
dataset_add = adsl,
new_vars = adsl_vars,
by = exprs(STUDYID, USUBJID)
by = exprs(!!!get_admiral_option("subject_keys"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, should use by_vars not by

…emoved "!!!" from get_admiral_options as we do not neednto use unquoting where it is an argument
@manciniedoardo
Copy link
Collaborator

@ProfessorP-beep sorry, would it be possible to please update the occasions where we have exprs(get_admiral_option("subject_keys") to just say get_admiral_option("subject_keys")? I believe that would be the right syntax. thanks

@ProfessorP-beep
Copy link
Collaborator Author

@manciniedoardo Already done. I realized my mistake after that last push. New one coming as soon as the checks are done.

@ProfessorP-beep
Copy link
Collaborator Author

Sorry, hold off on reviewing on minute. Some of the changes weren't pushed through.

@bms63
Copy link
Collaborator

bms63 commented Jun 3, 2024

and thanks @ProfessorP-beep for seeing this through!! This is how it works on the team :) We do PRs and I get a little huffy and puffy and ask funny questions - which usually are me being paranoid.

@rossfarrugia
Copy link
Collaborator

Thanks @bms63 - all fair questions, but i guess these all would have been discussed when we first added this option. Now that we have it offered in the package, we just need to make sure it works :)

Copy link
Collaborator

@bundfussr bundfussr left a comment

Choose a reason for hiding this comment

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

There are a few missed occurrences:

(base) bundfuss@rstudio:(templates)> grep USUBJID *.R
ad_adlbhy.R:  select(STUDYID, USUBJID, TRT01A, PARAMCD, LBSEQ, ADT, AVISIT, ADY, AVAL, ANRHI, CRIT1, CRIT1FL)
ad_adlbhy.R:  select(STUDYID, USUBJID, TRT01A) %>% # add AVISIT, ADT for by visit
ad_adlbhy.R:  select(STUDYID, USUBJID, TRT01A, CRIT1FL, BILI_CRITFL) %>% # add AVISIT, ADT for by visit
ad_advs.R:  #   by_vars = exprs(STUDYID, USUBJID, PARAMCD, BASETYPE),

@@ -159,7 +159,7 @@ adex <- adex %>%
)
),
dataset_add = adex,
by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars)
by_vars = c(get_admiral_option("subject_keys"), exprs(!!!adsl_vars))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
by_vars = c(get_admiral_option("subject_keys"), exprs(!!!adsl_vars))
by_vars = c(get_admiral_option("subject_keys"), adsl_vars)

Other occurrences should be updated as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Gotcha, I'll take a look at these. I think I was getting some error messages when using this with select(), but I'll look again and post it here if it comes up.

@@ -165,7 +165,7 @@ adeg <- adeg %>%
) %>%
# Derive QTLCR
derive_param_qtc(
by_vars = exprs(STUDYID, USUBJID, !!!adsl_vars, VISIT, VISITNUM, EGTPT, EGTPTNUM, ADTM, ADY),
by_vars = c(get_admiral_option("subject_keys"), exprs(!!!adsl_vars, VISIT, VISITNUM, EGTPT, EGTPTNUM, ADTM, ADY)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
by_vars = c(get_admiral_option("subject_keys"), exprs(!!!adsl_vars, VISIT, VISITNUM, EGTPT, EGTPTNUM, ADTM, ADY)),
by_vars = c(get_admiral_option("subject_keys"), adsl_vars, exprs(VISIT, VISITNUM, EGTPT, EGTPTNUM, ADTM, ADY)),

Other occurrences should be updated as well.

Copy link
Collaborator

Choose a reason for hiding this comment

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

@ProfessorP-beep did this one need an update?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oops looks like I missed it. Can update in a bit.

@@ -245,7 +245,7 @@ advs <- derive_vars_merged_lookup(
```{r, eval=TRUE, echo=FALSE}
advs_param <- distinct(advs, USUBJID, PARAMCD, VSTESTCD)

dataset_vignette(advs_param, display_vars = exprs(USUBJID, VSTESTCD, PARAMCD))
dataset_vignette(advs_param, display_vars = exprs(!!get_admiral_option("subject_keys")[[2]], VSTESTCD, PARAMCD))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Either we should update line 246 as well or we should not update this line.

@@ -219,7 +219,7 @@ advs <- tribble(
derive_vars_merged(
adsl,
dataset_add = advs,
by_vars = exprs(USUBJID),
by_vars = exprs(!!get_admiral_option("subject_keys")[[2]]),
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks confusing to me. We don't have any rules or convention on the number of elements in "subject_keys" or which variable is placed where. You could have exprs(USUBJID, STUDYID), exprs(STUDYID, SITEID, SUBJID), or exprs(USUBJID). I.e., selecting a certain element is not a good idea because in general you don't know what you get.

I would either add STUDYID to the data and use get_admiral_option("subject_keys") instead of exprs(!!get_admiral_option("subject_keys")[[2]]) or just leave it as it is.

@bms63 , @rossfarrugia , what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

add STUDYID to the data and use get_admiral_option("subject_keys") would be my preference. i don't like the [[2]] option either - as risky for future robustness.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This is being used in derive_var_trtemfl() as well. I flagged as concerning for me #2362 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hi @ProfessorP-beep do you have time to make these final changes today?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yea, I should be able to get to it this afternoon / early evening.

@ProfessorP-beep
Copy link
Collaborator Author

and thanks @ProfessorP-beep for seeing this through!! This is how it works on the team :) We do PRs and I get a little huffy and puffy and ask funny questions - which usually are me being paranoid.

No problem! I'm also learning a lot more so this is cool. I'm looking through the discussion now.

… can be used instead of subsetting with []. Replaced instances of !!!adsl_vars with just adsl_vars. Found other instances of USUBJID, STUDYID and replaced with get_admiral_optios("subject_keys") where errors didnt occur from the change.
…dmiral_options to USUBJID, STUDYID inside of select() functions to see if thats why scripts couldnt be executed
…ide the exprs() argument when defining by_vars
@@ -43,7 +43,7 @@ adlb_annotated <- adlb %>%
)
)
) %>%
select(STUDYID, USUBJID, TRT01A, PARAMCD, LBSEQ, ADT, AVISIT, ADY, AVAL, ANRHI, CRIT1, CRIT1FL)
select(USUBJID, STUDYID, TRT01A, PARAMCD, LBSEQ, ADT, AVISIT, ADY, AVAL, ANRHI, CRIT1, CRIT1FL)
Copy link
Collaborator

Choose a reason for hiding this comment

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

why was this one left behind with just the order of USUBJID and STUDYID swapped? noticed this by chance as was using this PR to prompt same changes in admiralonco. please double check any others

Copy link
Collaborator

Choose a reason for hiding this comment

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

as FYI should be select(!!!get_admiral_option("subject_keys"), TRT01A, ...etc)

@bms63
Copy link
Collaborator

bms63 commented Jun 5, 2024

@bundfussr @rossfarrugia @manciniedoardo - This update isn't critical to me for 1.1. Can we implement for 1.2 as it is actually quite large and seems to be opening lots of questions?

@manciniedoardo
Copy link
Collaborator

@bundfussr @rossfarrugia @manciniedoardo - This update isn't critical to me for 1.1. Can we implement for 1.2 as it is actually quite large and seems to be opening lots of questions?

Ok, let's leave until 1.2 to ensure we do this right and don't have to come back to it later. I still think it's an important update to make, and we can definitely still leverage all the work done by @ProfessorP-beep in this PR, but what we have now is not wrong per se, just a bit inconsistent.

@bms63
Copy link
Collaborator

bms63 commented Jun 5, 2024

Hi @ProfessorP-beep, we can talk about this tomorrow, but going to pause on this PR until after we ship 1.1 release. This will be our first PR into 1.2!

…ed, tested rmd and testthat files, but more test files should be addressed and tested where USUBJID and STUDYID are used.
@ProfessorP-beep
Copy link
Collaborator Author

Hi @ProfessorP-beep, we can talk about this tomorrow, but going to pause on this PR until after we ship 1.1 release. This will be our first PR into 1.2!

Sounds good, I'm just gonna push the additional changes I've done since then. There is probably still some review to be done to make sure all cases are addressed.

Copy link

This Pull Request is stale because it has not been worked on in 15 days.

@github-actions github-actions bot added the stale label Jun 22, 2024
@bms63 bms63 removed the stale label Jun 23, 2024
Copy link

github-actions bot commented Jul 9, 2024

This Pull Request is stale because it has not been worked on in 15 days.

@github-actions github-actions bot added the stale label Jul 9, 2024
@bms63 bms63 closed this Aug 21, 2024
@bms63 bms63 deleted the 2415-general-issue-make-subject-keys-flexible-in-all-functions branch September 9, 2024 12:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

General Issue: Make subject keys flexible in all functions
5 participants