Skip to content

Commit

Permalink
Merge pull request #106 from pharmaverse/Enhancement-implement-CI-wor…
Browse files Browse the repository at this point in the history
…kflows-based-on-admiralci

Enhancement: implemented relevant CI workflows from admiralci
  • Loading branch information
m-kolomanski authored Nov 5, 2024
2 parents d4175de + a41c3b0 commit c8240ab
Show file tree
Hide file tree
Showing 17 changed files with 190 additions and 37 deletions.
80 changes: 80 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Source: https://github.com/pharmaverse/admiralci
# Stripped down version of admiralci checks. Good for
# the developement process. When package is ready to
# be published, revisit and add release-related
# workflows.
name: admiral CI/CD Workflows

on:
workflow_dispatch:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: admiral-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true

env:
R_VERSION: "release"

jobs:
get_r_version:
name: Get R version
runs-on: ubuntu-latest
outputs:
r-version: ${{ steps.get_r_version.outputs.R_VERSION }}
steps:
- name: Get R Version for Downstream Container Jobs
id: get_r_version
run: echo "R_VERSION=$R_VERSION" >> $GITHUB_OUTPUT
shell: bash
spellcheck:
name: Spelling
uses: pharmaverse/admiralci/.github/workflows/spellcheck.yml@main
if: github.event_name == 'pull_request'
needs: get_r_version
with:
r-version: "${{ needs.get_r_version.outputs.r-version }}"
linter:
name: Lint
uses: pharmaverse/admiralci/.github/workflows/lintr.yml@main
needs: get_r_version
if: github.event_name == 'pull_request'
with:
r-version: "${{ needs.get_r_version.outputs.r-version }}"
man-pages:
name: Man Pages
uses: pharmaverse/admiralci/.github/workflows/man-pages.yml@main
if: github.event_name == 'pull_request'
needs: get_r_version
with:
r-version: "${{ needs.get_r_version.outputs.r-version }}"
tests:
name: Tests
runs-on: ubuntu-latest
needs: get_r_version
container:
image: "ghcr.io/pharmaverse/admiralci-${{ needs.get_r_version.outputs.r-version }}:latest"
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install dependencies
run: |
Rscript -e 'remotes::install_deps(dependencies = TRUE)'
- name: Run tests
shell: Rscript {0}
run: |
devtools::load_all(".")
devtools::test()
check:
name: Check
uses: pharmaverse/admiralci/.github/workflows/r-cmd-check.yml@main
if: github.event_name == 'pull_request'
with:
error-on: error
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters:
object_name_linter = object_name_linter(
styles = c("snake_case", "SNAKE_CASE")
),
object_usage_linter = NULL
object_usage_linter = NULL,
trailing_blank_lines_linter = NULL
)
encoding: "UTF-8"
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,4 @@ Suggests:
lintr (>= 3.1.2),
testthat (>= 3.0.0)
Config/testthat/edition: 3
Language: en-US
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(as_factor_preserve_label)
export(calculate_summary_stats)
export(create_conc)
export(create_dose)
export(filter_breaks)
export(flexible_violinboxplot)
export(format_data)
export(general_lineplot)
Expand Down Expand Up @@ -58,7 +59,10 @@ importFrom(ggplot2,geom_errorbar)
importFrom(ggplot2,geom_line)
importFrom(ggplot2,geom_point)
importFrom(ggplot2,ggplot)
importFrom(ggplot2,ggplot_build)
importFrom(ggplot2,ggplot_gtable)
importFrom(ggplot2,labs)
importFrom(grid,convertUnit)
importFrom(htmlwidgets,JS)
importFrom(logger,log_debug)
importFrom(logger,log_error)
Expand Down
2 changes: 1 addition & 1 deletion R/calculate_summary_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#' This function calculates various summary statistics for formatted output of PKNCA::pk.nca().
#'
#' @param input_groups A character vector specifying the columns to group by.
#' Here. the hierachrical order matters
#' Here. the hierarchical order matters
#' @param res_pknca A data frame containing results of
#' Non Compartmental Analysis using PKNCA package
#' @return A data frame with summary statistics for each group and parameter.
Expand Down
28 changes: 15 additions & 13 deletions R/filter_breaks.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ filter_breaks <- function(breaks = NA,
plot = plot,
min_cm_distance = 0.5,
axis = "x") {

breaks <- unique(na.omit(sort(breaks)))
plot_build <- ggplot_build(plot)
plot_table <- ggplot_gtable(plot_build)

# Extract axis scale information
if (axis == "x") {
scale_range <- plot_build$layout$panel_params[[1]]$x.range
Expand All @@ -29,21 +29,23 @@ filter_breaks <- function(breaks = NA,
} else {
stop("Error: Invalid axis specified. Use 'x' or 'y'.")
}

# Identify the panel grob
panel_index <- which(sapply(plot_table$grobs,
function(x) grepl("panel", x$name)))

if (length(panel_index) == 0) {
stop("Error: Panel grob not found.")
}
panel <- plot_table$grobs[[panel_index]]

# Extract the panel border grob to get the width or height
panel_border <- panel$children[[which(sapply(panel$children,
function(x) {
grepl("panel.border", x$name)}))]]

panel_border <- panel$children[[
which(sapply(panel$children, function(x) {
grepl("panel.border", x$name)
}))
]]

# Convert panel width or height to cm
if (axis == "x") {
panel_size_cm <- grid::convertUnit(panel_border$width,
Expand All @@ -54,15 +56,15 @@ filter_breaks <- function(breaks = NA,
unitTo = "cm",
valueOnly = TRUE)
}

# Calculate the distance between breaks in cm
break_distances <- diff(breaks) / diff(scale_range) * panel_size_cm

# Filter only breaks that satisfy the minimum distance
filt_breaks <- breaks[1]

for (i in 2:length(breaks)) {

# Take latest selected break and calculate its distance
b0 <- filt_breaks[length(filt_breaks)]
bdist <- (breaks[i] - b0) / diff(scale_range) * panel_size_cm
Expand Down
29 changes: 15 additions & 14 deletions R/general_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ general_lineplot <- function(
DOSEA = factor(DOSEA),
id_var = interaction(!!!syms(colorby_var), sep = ", ")
)

# If there are predose records duplicate them in the previous line so they are considered
if ("ARRLT" %in% names(preprocessed_data) &&
any(preprocessed_data$ARRLT < 0 & preprocessed_data$AFRLT > 0)) {
Expand Down Expand Up @@ -113,8 +113,7 @@ general_lineplot <- function(
} else {
"AFRLT"
}



plt <- tern::g_ipp(
df = preprocessed_data,
xvar = time,
Expand All @@ -139,21 +138,23 @@ general_lineplot <- function(

if (xaxis_scale == "Log") {
plt <- plt +
scale_y_continuous(trans = scales::pseudo_log_trans(base = 10, sigma = 1)) +
scale_y_continuous(trans = scales::pseudo_log_trans(base = 10, sigma = 1)) +
labs(y = paste0("Log 10 - ", plt$labels$y))

custom_label <- function(x) {

ifelse(x == 1e-3, 0, scales::trans_format("log10", scales::math_format(10^x)))
}

plt <- plt %+% dplyr::mutate(preprocessed_data, AVAL = ifelse(AVAL == 1e-3, 0, AVAL)) %>%
+
scale_y_continuous(
trans = scales::pseudo_log_trans(base = 10, sigma = 1),
breaks = c(-Inf, 10^seq(from = -3, to = ceiling(log10(max(plt$data["AVAL"], na.rm = T))))) %>%
filter_breaks(plot = plt, min_cm_distance = 20, axis = "y"),
labels = scales::trans_format("log10", scales::math_format(10^.x))

plt <- plt %+% dplyr::mutate(preprocessed_data, AVAL = ifelse(AVAL == 1e-3, 0, AVAL)) %>%
+
scale_y_continuous(
trans = scales::pseudo_log_trans(base = 10, sigma = 1),
breaks = c(
-Inf, 10^seq(from = -3, to = ceiling(log10(max(plt$data["AVAL"], na.rm = TRUE))))
) %>%
filter_breaks(plot = plt, min_cm_distance = 20, axis = "y"),
labels = scales::trans_format("log10", scales::math_format(10^.x))
)
}
return(plt)
Expand Down
2 changes: 1 addition & 1 deletion R/imports.R
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#' @importFrom logger log_trace log_debug log_info log_warn log_error log_fatal
NULL
NULL
2 changes: 1 addition & 1 deletion R/reshape_PKNCA_results.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#'
#' @param res_nca The output of PKNCA::pk.nca
#'
#' @returns A data frame (finalres2) which provides an easy overview on the results from the NCA
#' @returns A data frame which provides an easy overview on the results from the NCA
#' in each profile/subject and how it was computed lambda (half life) and the results
#' of the NCA parameters (cmax, AUC, AUClast)
#'
Expand Down
2 changes: 1 addition & 1 deletion R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
logger::log_formatter(logger::formatter_glue)
logger::log_threshold(logger::TRACE)
logger::log_appender(logger::appender_console, namespace = "global")
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ devtools::load_all()
aNCA::run_app()
```

Have fun running your tailored Non-Compartemental Analysis!
Have fun running your tailored Non-Compartmental Analysis!

<!--
## Contribute as developer
Expand Down
40 changes: 40 additions & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
ADNCA
ADPP
AFRLT
AUClast
AVAL
BLQ
Bärtschi
CDISC
DOSEA
DOSNO
EVID
IQROUTE
NCA
PCSPEC
PKNCA
Pharmacokinetic
Pre
RO
RStudio
STUDYID
USUBJID
USUBJIDs
analyte
analytes
anonymized
anonymizes
cmax
csv
ggplot
nca
pharmacokinetic
pknca
plotly
pptest
pre
sas
summarization
timepoint
visualizable
xpt
2 changes: 1 addition & 1 deletion inst/shiny/tabs/nca.R
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ output$preslopesettings <- DT::renderDataTable({
scrollX = TRUE,
scrollY = TRUE,
lengthMenu = list(c(10, 25, -1), c("10", "25", "All")),
pageLength = -1,
pageLength = -1,
fixedHeader = TRUE
)
) %>%
Expand Down
2 changes: 1 addition & 1 deletion man/calculate_summary_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/filter_breaks.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/reshape_pknca_results.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-general_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ sample_data <- data.frame(
AVALU = rep("ng/mL", 24),
DOSEA = rep(35, 24)
)
# testthat::test_file("tests/testhat/test-general_lineplot.R")

describe("general_lineplot functions correctly", {
it("returns a ggplot object", {
p <- general_lineplot(
Expand Down

0 comments on commit c8240ab

Please sign in to comment.