Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
122 commits
Select commit Hold shift + click to select a range
4f7a2e8
draft: start developing a new lambda_slope_plot fun
Gero1999 Aug 25, 2025
2f76e49
fix: loop difficulties and still problems with start != 0
Gero1999 Aug 27, 2025
c0ef020
draft: customdata to use
Gero1999 Aug 27, 2025
cabdc38
fix: get_res uses PPSTRES instead of PPORRES
Gero1999 Aug 28, 2025
76338b8
feat: input for plots is pknca_data & namespace PKNCA funs
Gero1999 Aug 28, 2025
daec410
draft: start trying to include get_halflife_plots in the server logic
Gero1999 Aug 28, 2025
08ef8d6
fix: adapt modules slope_selector, manual_slopes_table
Gero1999 Aug 29, 2025
862ad2f
optimize: generation reactivity & reduce edit-table columns
Gero1999 Aug 29, 2025
99c195d
draft: try to change customdata for a more efficient way (not working)
Gero1999 Aug 29, 2025
7e4ab70
feat: make plots interactive with themselves and the table
Gero1999 Sep 3, 2025
c8b08e0
test push
Gero1999 Sep 3, 2025
3676fe2
refactor: handle_plotly_click
Gero1999 Sep 3, 2025
02b5f3e
draft: selections still not working well
Gero1999 Sep 3, 2025
85ea167
draft: manual exclusions still not workng
Gero1999 Sep 3, 2025
16f55db
rm slopes_pknca_groups as input for modules, only change affected plots
Gero1999 Sep 4, 2025
d83e95c
enhance: keep in plot manual changes when user selects more analytes,…
Gero1999 Sep 5, 2025
e0dcd12
rm filter_slopes, apply instead manual_slopes in PKNCA_update_data_obj
Gero1999 Sep 5, 2025
bed581c
fix: issue with MD due to result merge without start/end
Gero1999 Sep 9, 2025
c67b0a3
optimize speed fun, sacrifice clarity (main problems: PKNCA funs)
Gero1999 Sep 9, 2025
84cb307
fix: fun in prev change has already considered start for line drawing
Gero1999 Sep 9, 2025
0bee541
draft: start working in changing reactivity to processed_pknca_data obj
Gero1999 Sep 9, 2025
882d4b9
handle new rules in plot update based on processed_pknca_data
Gero1999 Sep 10, 2025
f8fd6ad
refactor: create new .update_pknca_with_rules
Gero1999 Sep 10, 2025
847032d
disconsider is.excluded.hl, is.included.hl
Gero1999 Sep 10, 2025
921a7a1
fix: allow all plots to keep interactivity (get_halflife_plot)
Gero1999 Sep 10, 2025
1444a06
fix: issues with efficient render
Gero1999 Sep 11, 2025
85960fc
fix: udpate search_subject choices only when data changes
Gero1999 Sep 11, 2025
d26ad10
dont use NCA_PROFILE, some points will not work if nominally classifi…
Gero1999 Sep 11, 2025
88a8991
fix: issue with update of plots for exclusions
Gero1999 Sep 11, 2025
1c1ad55
refactor: create a module page_and_searcher.R
Gero1999 Sep 11, 2025
0e9a1cd
refactor: rm slopes_pknca_groups from slope_selector.R & reduce outpu…
Gero1999 Sep 11, 2025
78ec71d
refactor: logic to handle plot generation in slope_selector.R
Gero1999 Sep 11, 2025
80d66b7
refactor: manual_slopes_override inside manual_slopes_table_server.R
Gero1999 Sep 11, 2025
dddc976
refactor: simplify all submodule out & renaming manual_slopes_table
Gero1999 Sep 11, 2025
f4317e2
fix: issue when changing intervals and plot_outputs()
Gero1999 Sep 11, 2025
1f425f7
refactor: add more docs, comments & rename hadnle_slopes_table > hand…
Gero1999 Sep 11, 2025
569402e
fix: issue with interval change when removing
Gero1999 Sep 11, 2025
e7af2a7
fix: issue when joining intervals with fixed names
Gero1999 Sep 11, 2025
b2b5a64
draft: try to incorporate slope plots in zip file (error due to names)
Gero1999 Sep 11, 2025
f3f2269
feat: include a group order for the plots
Gero1999 Sep 12, 2025
7b1e69a
refactor: lintr
Gero1999 Sep 12, 2025
5fb2953
refactor: rm return for implicit output
Gero1999 Sep 12, 2025
dc227e8
rename: lambda_slope_plot.R > get_halflife_plot.R
Gero1999 Sep 12, 2025
c39ac39
fix: typpo in get_halflife_plot.R
Gero1999 Sep 12, 2025
f9ba366
draft: new tests for get_halflife_plot
Gero1999 Sep 12, 2025
efa0065
draft: keep going with tests
Gero1999 Sep 12, 2025
94b373d
draft: change fun for get_halflife_plots
Gero1999 Sep 15, 2025
ab62e7c
merge: solved conflict (tab_nca.R) by keeping origin but rm filter_sl…
Gero1999 Sep 15, 2025
1d9ad36
fix: make reading of columns before & solve issue with distinct
Gero1999 Sep 15, 2025
a339f98
test: reach 100% cov & add in setup exclude/include cols for PKNCA
Gero1999 Sep 15, 2025
4209301
rename: to get_halflife_plots & refactor with describe/it the tests
Gero1999 Sep 15, 2025
95136da
draft: new tests for utils-slope_selector.R
Gero1999 Sep 15, 2025
8f63952
man: add new manuals for the processing
Gero1999 Sep 15, 2025
b97b2ac
man: roxygenise
Gero1999 Sep 15, 2025
3135116
fix: handle_interval_change when intervals do not have all group_vars
Gero1999 Sep 15, 2025
20999ae
fix: .update_pknca_with_rules when not all group columns are in input
Gero1999 Sep 15, 2025
6c8e920
test, draft: continue working in test-utils_slope_selector.R
Gero1999 Sep 15, 2025
6ab37f2
fix: typpo get_halflife_plots
Gero1999 Sep 15, 2025
38f5dbf
rm duplicated test & make new one for exp error
Gero1999 Sep 15, 2025
2066d87
rm unused fun in utils-slope_selector (update_plots_with_rules)
Gero1999 Sep 16, 2025
7989d78
feat: include slope plots in zip folder
Gero1999 Sep 16, 2025
6881e54
refactor: tests utils-slope_selector logic
Gero1999 Sep 16, 2025
ae64689
refactor: tests in get_halflife_plots
Gero1999 Sep 16, 2025
df8a87d
rm: arg unneded from detect_pknca_data_changes (hl_cols)
Gero1999 Sep 16, 2025
e0f350a
refactor: lintr
Gero1999 Sep 16, 2025
5628c01
docs: update PKNCA.R & rename funs in utils-slope_selector.R
Gero1999 Sep 16, 2025
ab9f9e5
man: update manuals
Gero1999 Sep 16, 2025
57f577a
docs: change documentation and manuals in get_halflife_plots.R
Gero1999 Sep 16, 2025
32210f1
zzz.R: add global vars
Gero1999 Sep 16, 2025
7bd5d1c
docs: add `` for column names in man
Gero1999 Sep 16, 2025
13940d8
lintr
Gero1999 Sep 16, 2025
bf46eae
add missing importFrom in general_meanplot
Gero1999 Sep 16, 2025
2b5f9eb
man: update
Gero1999 Sep 16, 2025
e805295
spelling: fix
Gero1999 Sep 16, 2025
cb5e042
fix: rm unused arg from detect_pknca_data_changes
Gero1999 Sep 16, 2025
fee08b2
fix: add-row + click crashes
Gero1999 Sep 17, 2025
0e6f9e8
fix: slopes table choices need to update upon setup changes
Gero1999 Sep 17, 2025
c1f3812
fix: add checks for exclusion-reasons before running NCA
Gero1999 Sep 17, 2025
e00c4e7
refactor: lintr
Gero1999 Sep 17, 2025
50ecaaf
draft: fix using tlast for plots limits
Gero1999 Sep 30, 2025
95b3107
fix: using tlast for plots limits
Gero1999 Oct 1, 2025
a6c4bf9
aesthetics: orderInput items in 1 line
Gero1999 Oct 1, 2025
b11af65
Merge branch 'main' into 553-enhancement-simplify_logic_slope_plots
Gero1999 Oct 2, 2025
92dbb96
merge main: solve zzz.R & update NAMESPACE
Gero1999 Oct 6, 2025
4ecf25f
fix: warning in test (console) due to expected missing record
Gero1999 Oct 6, 2025
e144f93
fix: expect error test msg
Gero1999 Oct 6, 2025
20e100d
fix: zzz.R global var missing
Gero1999 Oct 6, 2025
b0ee03a
merge: solve conflict NAMESPACE
Gero1999 Oct 6, 2025
0d840d3
test: add exp error case for invalid TYPE
Gero1999 Oct 6, 2025
03efeb3
silence warnings in tests for exp warning
Gero1999 Oct 6, 2025
fe17c25
docs: change docs so { } do not produce issues
Gero1999 Oct 6, 2025
8367d90
merge main: solved conflict in testthat/setup.R
Gero1999 Oct 10, 2025
e54a3b2
Merge remote-tracking branch 'origin/main' into 553-enhancement-simpl…
Gero1999 Oct 13, 2025
a4f826b
change plotid names to allow HTML correct download
Gero1999 Oct 22, 2025
85e31ed
include manual_slopes rules in session$userData
Gero1999 Oct 22, 2025
8b39738
fix: tlast exclude homogenized with others
Gero1999 Oct 22, 2025
1ef1580
rm commented code & roxygenise
Gero1999 Oct 22, 2025
039d213
Merge pull request #731 from pharmaverse/725-enhancement/slope-rules-…
Gero1999 Oct 22, 2025
d25281c
test: adapt test to new plot ID
Gero1999 Oct 23, 2025
82f38d7
fix: new plot ID needs to be considered in handle_interval_change
Gero1999 Oct 23, 2025
be11957
use for additional_analysis_server the raw pknca_data
Gero1999 Nov 12, 2025
feda4c0
merge: solve conflicts and replace NCA_PROFILE > ATPTREF
Gero1999 Nov 12, 2025
62788c9
fix: pkcg01 example typpo
Gero1999 Nov 25, 2025
f5b4f71
merge: solve conflicts (), rm files removed in main, roxygenise
Gero1999 Dec 5, 2025
ea6159a
disconsider middle BLQ points in half life plots
Gero1999 Jan 2, 2026
5ee4696
Merge: conflicts with arg params removed. just rm from current, and k…
Gero1999 Jan 2, 2026
de68700
general style, nitpicks & issues: apply refactor suggestions
Gero1999 Jan 5, 2026
47a59de
apply suggested changes
Gero1999 Jan 6, 2026
f80637f
mv from /R > /functions most utils-slope_selector
Gero1999 Jan 6, 2026
edcd5a7
tmp fix: exclusion rm after run NCA crashes App
Gero1999 Jan 6, 2026
7b544da
refactor: lintr
Gero1999 Jan 7, 2026
3ff0937
fix: plot tests failing due to accidental change in marker size
Gero1999 Jan 7, 2026
b5e4082
man: roxygenise
Gero1999 Jan 7, 2026
1facc21
fix: test-pk_dose_qc_plot.R exporting ggplotly
Gero1999 Jan 7, 2026
02fe1e5
fix: test typpo
Gero1999 Jan 7, 2026
9bb2d88
mv tests for moved funs in /functions to /inst/shiny
Gero1999 Jan 7, 2026
4bb5b65
refactor: lintr
Gero1999 Jan 7, 2026
082c140
fix: next_page, previous_page overjumping
Gero1999 Jan 7, 2026
2993778
rm shinyjs::useShinyjs()
Gero1999 Jan 7, 2026
df40ab1
Merge: accept both changes for all conflicting files (setup.R, PKNCA_…
Gero1999 Jan 9, 2026
6d26ed2
fix: line unclosed for tests
Gero1999 Jan 9, 2026
6f0ea86
man: roxygenise
Gero1999 Jan 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,13 @@ export(apply_mapping)
export(calculate_f)
export(calculate_ratios)
export(calculate_summary_stats)
export(check_slope_rule_overlap)
export(convert_volume_units)
export(create_metabfl)
export(create_start_impute)
export(detect_study_types)
export(dose_profile_duplicates)
export(export_cdisc)
export(filter_breaks)
export(filter_slopes)
export(flexible_violinboxplot)
export(format_pkncaconc_data)
export(format_pkncadata_intervals)
Expand All @@ -45,7 +43,6 @@ export(get_label)
export(interval_add_impute)
export(interval_remove_impute)
export(l_pkcl01)
export(lambda_slope_plot)
export(multiple_matrix_ratios)
export(parse_annotation)
export(pivot_wider_pknca_results)
Expand All @@ -70,11 +67,11 @@ import(rlistings)
import(tidyr)
importFrom(PKNCA,exclude)
importFrom(PKNCA,pk.calc.c0)
importFrom(PKNCA,pk.nca)
importFrom(dplyr,"%>%")
importFrom(dplyr,`%>%`)
importFrom(dplyr,across)
importFrom(dplyr,add_count)
importFrom(dplyr,all_of)
importFrom(dplyr,any_of)
importFrom(dplyr,arrange)
importFrom(dplyr,bind_rows)
Expand All @@ -83,6 +80,7 @@ importFrom(dplyr,distinct)
importFrom(dplyr,everything)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,group_split)
importFrom(dplyr,inner_join)
importFrom(dplyr,left_join)
importFrom(dplyr,mutate)
Expand All @@ -97,10 +95,17 @@ importFrom(dplyr,where)
importFrom(flextable,flextable)
importFrom(formatters,var_labels)
importFrom(ggplot2,aes)
importFrom(ggplot2,facet_wrap)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplot_build)
importFrom(ggplot2,ggplot_gtable)
importFrom(ggplot2,labs)
importFrom(ggplot2,scale_alpha_manual)
importFrom(ggplot2,scale_colour_manual)
importFrom(ggplot2,scale_shape_manual)
importFrom(ggplot2,scale_x_continuous)
importFrom(ggplot2,theme_bw)
importFrom(grid,convertUnit)
importFrom(magrittr,`%>%`)
importFrom(methods,is)
Expand All @@ -114,23 +119,24 @@ importFrom(officer,ph_location_type)
importFrom(officer,ph_slidelink)
importFrom(officer,ph_with)
importFrom(officer,read_pptx)
importFrom(plotly,add_lines)
importFrom(plotly,add_trace)
importFrom(plotly,config)
importFrom(plotly,ggplotly)
importFrom(plotly,layout)
importFrom(plotly,plot_ly)
importFrom(plotly,style)
importFrom(plotly,plotly_build)
importFrom(purrr,imap)
importFrom(purrr,pmap)
importFrom(purrr,pmap_chr)
importFrom(purrr,reduce)
importFrom(rlang,expr)
importFrom(rlang,set_names)
importFrom(rlang,sym)
importFrom(rlang,syms)
importFrom(stats,as.formula)
importFrom(stats,lm)
importFrom(stats,median)
importFrom(stats,na.omit)
importFrom(stats,predict)
importFrom(stats,sd)
importFrom(stats,setNames)
importFrom(stringr,str_glue)
Expand Down
59 changes: 58 additions & 1 deletion R/PKNCA.R
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ PKNCA_create_data_object <- function(adnca_data, nca_exclude_reason_columns = NU
# Set default settings
df_conc$is.excluded.hl <- FALSE
df_conc$is.included.hl <- FALSE
df_conc$REASON <- NA
df_conc$REASON <- ""
Copy link

Copilot AI Nov 12, 2025

Choose a reason for hiding this comment

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

Changed default REASON from NA to empty string. This is a behavior change that may affect downstream code expecting NA values. Verify that all code checking for missing reasons handles empty strings correctly (e.g., line 739 uses nchar check, which works correctly with empty strings).

Suggested change
df_conc$REASON <- ""
df_conc$REASON <- NA_character_

Copilot uses AI. Check for mistakes.
df_conc$exclude_half.life <- FALSE

# Create PKNCA conc object
Expand Down Expand Up @@ -197,6 +197,8 @@ PKNCA_create_data_object <- function(adnca_data, nca_exclude_reason_columns = NU
#'
#' Step 5: Impute start values if requested
#'
#' Step 6: Indicate points excluded / selected manually for half-life
#'
#' Note*: The function assumes that the `adnca_data` object has been
#' created using the `PKNCA_create_data_object()` function.
#'
Expand All @@ -205,6 +207,9 @@ PKNCA_create_data_object <- function(adnca_data, nca_exclude_reason_columns = NU
#' @param selected_analytes User selected analytes
#' @param selected_profile User selected dose numbers/profiles
#' @param selected_pcspec User selected specimen
#' @param hl_adj_rules A data frame containing half-life adjustment rules. It must
#' contain group columns and rule specification columns;
#' TYPE: (Inclusion, Exclusion), RANGE: (start-end).
#' @param should_impute_c0 Logical indicating whether to impute start concentration values
#' @param exclusion_list List of exclusion reasons and row indices to apply to the
#' concentration data. Each item in the list should have:
Expand All @@ -226,6 +231,7 @@ PKNCA_update_data_object <- function( # nolint: object_name_linter
selected_profile,
selected_pcspec,
should_impute_c0 = TRUE,
hl_adj_rules = NULL,
exclusion_list = NULL
) {

Expand Down Expand Up @@ -269,6 +275,10 @@ PKNCA_update_data_object <- function( # nolint: object_name_linter
PCSPEC %in% selected_pcspec
)

# Update concentration data to indicate points excluded / selected manually for half-life
if (!is.null(hl_adj_rules)) {
data <- update_pknca_with_rules(data, hl_adj_rules)
}
data
}

Expand Down Expand Up @@ -650,6 +660,53 @@ PKNCA_hl_rules_exclusion <- function(res, rules) { # nolint
res
}


#' Checks Before Running NCA
#'
#' This function checks that:
#' 1) exclusions_have_reasons: all manually excluded half-life points in the concentration data
#' have a non-empty reason provided. If any exclusions are missing a reason, it stops with an error
#' and prints the affected rows (group columns and time column).
#'
#' @param processed_pknca_data A processed PKNCA data object.
#' @param exclusions_have_reasons Logical; Check that all exclusions have a reason (default: TRUE).
#'
#' @return The processed_pknca_data object (input), if checks are successful.
#'
#' @details
#' - If any excluded half-life points are missing a reason, an error is thrown.
#' - If no exclusions or all have reasons, the function returns the input object.
#' - Used to enforce good practice/documentation before NCA calculation.
#'
#' @examples
#' # Suppose processed_pknca_data is a valid PKNCA data object
#' # check_valid_pknca_data(processed_pknca_data)
check_valid_pknca_data <- function(processed_pknca_data, exclusions_have_reasons = TRUE) {
if (exclusions_have_reasons) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

issue: So setting one of the arguments of the function to FALSE means the function does nothing? If the module / logic / user calling the function knows beforehand that exclusions don't have reasons, then the function should not be called anyway.

exclusions_have_reasons <- # some logic to check
if (exclusions_have_reasons) {
  processed_pknca_data <- checks_before_running_nca(processed_pknca_data)
}

or if we want to make this a function restriction, then the function itself should check it, not rely on the calling logic to tell it the data meets some requirements or not.

checks_before_running_nca <- function(processed_pknca_data) {
  exclusions_have_reasons <- # ... some logic to check
  if (!exclusions_have_reasons) {
    warning("Exclusions do not have reasons, could not process the data")
    return(processed_pknca_data)
  }
  # ... rest of the function
}

Copy link
Collaborator Author

@Gero1999 Gero1999 Jan 6, 2026

Choose a reason for hiding this comment

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

you might be right but I don't follow this point. The arg allows the user to decide if they want to make that check or not. It is not for them to escape the check because they don't need it, but more in case they just simply don't want to comply with it

For now we only have this check, but is likely that we keep increasing it with more

excl_hl_col <- processed_pknca_data$conc$columns$exclude_half.life

if (!is.null(excl_hl_col)) {
data_conc <- processed_pknca_data$conc$data
conc_groups <- group_vars(processed_pknca_data$conc)
time_col <- processed_pknca_data$conc$columns$time

missing_reasons <- data_conc[[excl_hl_col]] & nchar(data_conc[["REASON"]]) == 0
missing_reasons_rows <- data_conc[missing_reasons, ] %>%
select(any_of(c(conc_groups, time_col)))

if (nrow(missing_reasons_rows) > 0) {
stop(
"No reason provided for the following half-life exclusions:\n",
"\n",
paste(capture.output(print(missing_reasons_rows)), collapse = "\n"),
"\n",
"Please go to `Slope Selection` table and include it"
)
}
}
}
processed_pknca_data
}
#' Add Exclusion Reasons to PKNCAdata Object
#'
#' This function adds exclusion reasons to the `exclude` column of the concentration object
Expand Down
3 changes: 2 additions & 1 deletion R/g_pkcg.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,15 @@ g_pkcg01_log <- function(data, ...) {
#' @importFrom ggplot2 aes scale_x_continuous labs
#' @importFrom tern g_ipp
#' @importFrom stats setNames
#' @importFrom plotly ggplotly layout
#'
#' @examples
#' adnca <- read.csv(system.file("shiny/data/example-ADNCA.csv", package = "aNCA"))
#' adnca <- subset(adnca, adnca$USUBJID %in% unique(adnca$USUBJID)[c(1, 2)])
#' attr(adnca[["AFRLT"]], "label") <- "Actual time from first dose"
#' attr(adnca[["AVAL"]], "label") <- "Analysis val"
#'
#' plots_lin <- pkcg01(adnca = adnca, xmax = 1)
#' plots_lin <- pkcg01(adnca = adnca, xmax = 1, scale = "LIN")
#'
#' @export
#' @author Gerardo Rodriguez
Expand Down
Loading