Skip to content

Conversation

@Gero1999
Copy link
Collaborator

@Gero1999 Gero1999 commented Nov 28, 2025

Issue

Closes #467

Description

Implemented the script file. It was made in order to eventually also be used using a settings file

Definition of Done

  • R Script export
  • Can be run independently and give same results as in app
  • Using aNCA functions

How to test

Do your choices in the App and export the ZIP folder. In the subfolder find the /code/session_script.R and run it. Compare the script outputs with the result files in the exported ZIP

Contributor checklist

  • Code passes lintr checks
  • Code passes all unit tests
  • New logic covered by unit tests
  • New logic is documented
  • App or package changes are reflected in NEWS
  • Package version is incremented

Notes to reviewer

Copilot AI review requested due to automatic review settings November 28, 2025 09:10
@Gero1999 Gero1999 linked an issue Nov 28, 2025 that may be closed by this pull request
3 tasks
@Gero1999 Gero1999 marked this pull request as ready for review November 28, 2025 09:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR implements an R script export feature that allows users to download an executable R script capturing their session configuration. The script can be run independently to reproduce the same NCA analysis results.

Key changes:

  • Added get_session_script_code() function to generate executable R scripts from templates with session data substitution
  • Moved and exported calculate_table_ratios_app() function from Shiny-specific code to the package API
  • Added session data capture in multiple Shiny modules to support script generation

Reviewed changes

Copilot reviewed 15 out of 15 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
R/get_session_script_code.R New function to parse templates and substitute session variables with actual values
R/ratio_calculations.R Added exported calculate_table_ratios_app() function (moved from internal Shiny code)
inst/shiny/www/templates/script_template.R Template for generating session-specific R scripts with placeholders for session data
inst/shiny/modules/tab_nca/nca_results.R Integration of script generation into the export ZIP functionality
inst/shiny/modules/tab_nca.R Captures settings, ratio_table, and slope_rules to session userData
inst/shiny/modules/tab_data/*.R Captures mapping, filters, and data paths to session userData
inst/shiny/modules/tab_nca/setup.R Removed duplicate ratio_table assignment
inst/shiny/functions/ratio_table.R Removed calculate_table_ratios_app() (moved to R/ratio_calculations.R)
man/*.Rd Documentation files for new and moved functions
NAMESPACE Export declaration for calculate_table_ratios_app()
inst/WORDLIST Added technical terms for spell checking
R/zzz.R Added calculate_ratio_app to global variables list

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.

Comment on lines +299 to +305
warning(
"Ratio ", ratio_table$PPTESTCD[i], " not computed.",
"No comparable groups found between RefGroups",
" (", ratio_table$RefGroups[i], ")",
"and TestGroups",
" (", ratio_table$TestGroups[i], ")"
)
Copy link

Copilot AI Nov 28, 2025

Choose a reason for hiding this comment

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

The warning message is missing spacing between sentences. Add a space after "not computed." to improve readability: "Ratio ", ratio_table$PPTESTCD[i], " not computed. No comparable groups found..."

Copilot uses AI. Check for mistakes.
apply relevant copilot suggestions

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings November 28, 2025 09:28
@Gero1999 Gero1999 review requested due to automatic review settings November 28, 2025 09:33
@Gero1999 Gero1999 marked this pull request as draft November 28, 2025 09:39
@Gero1999
Copy link
Collaborator Author

Gero1999 commented Jan 9, 2026

@Shaakon35

when there is a duplicate in the app, a pop-up appears and you can exclude one point

I opened a new issue (#886) to address this apart, as it will need to modify further more other files from main

adnca created in cdisc_datasets$adnca is not exactly equal to the one in the zip file.

The differences I saw where DTYPE and the duplicates. So it would be related again with #886

ADPP and PP don't have the correct pk parameters, the selection of pk parameter is not correct in the script

Now it has been corrected in the last commits


@js3110

I am still getting this message every time I checkout your branch:

Warning message:
── Conflicts ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── aNCA conflicts
──
✖ `calculate_table_ratios_app` masks `aNCA::calculate_table_ratios_app()`.
ℹ Did you accidentally source a file rather than using `load_all()`?
  Run `rm(list = c("calculate_table_ratios_app"))` to remove the conflicts. 

This is expected to happen when changing between dev-branches. This shouldn't present a problem to the user and neither to us once this change is stabilized.

@Gero1999 Gero1999 marked this pull request as ready for review January 9, 2026 10:25
@Gero1999 Gero1999 requested a review from Shaakon35 January 9, 2026 14:21
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ok, but currently the function needs the session object, so you have to go through the app anyway? I would agree if the function also accepted a settings file and had a more generic name, but currently it does not.

At the very least, if we want to implement it this way right now and then add the functionality of parsing a settings file instead of session object, we should have

  • more generic name
  • # TODO comments with link or number of appropriate issue to rely that intent.

Comment on lines 95 to 97
if (nrow(obj) == 0) {
return("data.frame()")
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

nitpick: This is redundant, as it is handled by lines 80-83

if (length(obj) == 0 && !is.null(obj)) {
    return(paste0(class(obj)[1], "()"))
  }

#' AdjustingFactor, TestGroups, RefGroups, PPTESTCD.
#' @returns The updated PKNCAresult object with added rows in the `result` data.frame.
#' @export
calculate_table_ratios_app <- function(res, ratio_table) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

+1

ratio_results <- vector("list", nrow(ratio_table))

# Loop through each row of the ratio_table
for (i in seq_len(nrow(ratio_table))) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Use apply instead of a for loop.


all_ratios <- data.frame()

for (ix in seq_along(match_cols)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: use apply or some other mapping columns, create a list and then bind all rows at once instead of adding rows to an empty data frame one by one.

@Gero1999
Copy link
Collaborator Author

At the very least, if we want to implement it this way right now and then add the functionality of parsing a settings file instead of session object, we should have: more generic name, TODO comments

I created a TODO and the implementation will be developed in #835. The name/refactoring of this function I will be done there just for easiness.

Here, in this PR, I removed the redundant check, renamed calculate_table_ratios_app > calculate_table_ratios & refactored to use apply

@Gero1999 Gero1999 requested a review from m-kolomanski January 12, 2026 09:07
@js3110
Copy link
Collaborator

js3110 commented Jan 12, 2026

LGTM :)

Copy link
Collaborator

@Shaakon35 Shaakon35 left a comment

Choose a reason for hiding this comment

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

Here we go!! Congratulations @Gero1999 👍

@Shaakon35
Copy link
Collaborator

@Gero1999 Can you add in the README, in the Description bullet list:

  • reproduce your NCA outside of the app, with the R script created

@Gero1999 Gero1999 linked an issue Jan 19, 2026 that may be closed by this pull request
4 tasks
@Gero1999 Gero1999 changed the title 467 enhancement/r script #467: Create R script to replicate App outputs Jan 19, 2026
@Gero1999 Gero1999 changed the title #467: Create R script to replicate App outputs Create R script to replicate App outputs (#467) Jan 19, 2026
Merge branch '467-enhancement/r-script' of https://github.com/pharmaverse/aNCA into 467-enhancement/r-script

# Conflicts:
#	DESCRIPTION
@Gero1999
Copy link
Collaborator Author

Issue with flags was partially solved here (de-selection of rules prevent color reporting of rows): #896

@Gero1999 Gero1999 marked this pull request as draft January 22, 2026 10:19
@Gero1999
Copy link
Collaborator Author

Gero1999 commented Jan 22, 2026

I will rework on this to properly incorporate the new aspects integrated in main:

  • BLQ imputation
  • additional grouping variables in ratios considered when requested
  • ZIP folder

I will include quick how-to-test for specifically these things to specifically review them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

5 participants