Skip to content
Open
3 changes: 2 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ Config/Needs/verdepcheck: tidyverse/dplyr, mllg/checkmate,
yihui/knitr, insightsengineering/nestcolor, rstudio/rmarkdown,
r-lib/testthat, tidyverse/tidyr
Config/Needs/website: insightsengineering/nesttemplate
Config/testthat/edition: 3
Encoding: UTF-8
Language: en-US
LazyData: true
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.2
Config/roxygen2/version: 8.1.1
8 changes: 5 additions & 3 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import(dplyr)
import(mcr)
importFrom(ggplot2,ggplot)
importFrom(magrittr,extract2)
importFrom(rlang,"!!")
importFrom(rlang,":=")
importFrom(rlang,.data)
importFrom(rlang,
"!!",
":=",
.data
)
importFrom(utils,getFromNamespace)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# goshawk 0.1.19.9001

* `g_scatterplot` was hard deprecated (#267).
* Code coverage has increased to over 90% (#268).
* Updated links to teal for the new location (#268).

# goshawk 0.1.19

Expand Down
2 changes: 0 additions & 2 deletions R/g_boxplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
checkmate::assert_numeric(ylim, len = 2)

# filter input data
data <- data %>%

Check warning on line 159 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=159,col=16,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
filter(!!sym(param_var) == biomarker)

if (!is.null(unit)) {
Expand All @@ -166,12 +166,12 @@
}
# extract the most common unit
# if there are ties, take the use alphabetic order
tmp_unit <- data %>%

Check warning on line 169 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=169,col=22,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
count(!!sym(unit)) %>%

Check warning on line 170 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=170,col=26,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
top_n(1, n) %>%

Check warning on line 171 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=171,col=19,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
arrange(!!sym(unit)) %>%

Check warning on line 172 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=172,col=28,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
slice(1) %>%

Check warning on line 173 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=173,col=16,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
select(!!sym(unit)) %>%

Check warning on line 174 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=174,col=27,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
as.character()
if (is.factor(data[[unit]])) {
unit <- levels(data[[unit]])[as.numeric(tmp_unit)]
Expand Down Expand Up @@ -217,7 +217,7 @@
if (length(x) == 0) {
return(FALSE)
}
return(is.finite(x))

Check warning on line 220 in R/g_boxplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_boxplot.R,line=220,col=5,[return_linter] Use implicit return behavior; explicit return() is not needed.
}

plot1 <- plot1 +
Expand Down Expand Up @@ -281,8 +281,6 @@
}




# Format font size
if (is_finite(font_size)) {
plot1 <- plot1 +
Expand Down
14 changes: 8 additions & 6 deletions R/g_correlationplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -262,19 +262,19 @@
t_param_var_y <- paste("PARAM", yaxis_param, sep = "_")
t_lbstresc_var_y <- paste("LBSTRESC", yaxis_param, sep = "_")

xaxis_param_loqs_data <- data %>%

Check warning on line 265 in R/g_correlationplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_correlationplot.R,line=265,col=33,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
mutate(
PARAM = !!sym(t_param_var_x), LBSTRESC = !!sym(t_lbstresc_var_x),
sym(loq_flag_var) == !!sym(loq_flag_var)
) %>%

Check warning on line 269 in R/g_correlationplot.R

View workflow job for this annotation

GitHub Actions / SuperLinter 🦸‍♀️ / Lint R code 🧶

file=R/g_correlationplot.R,line=269,col=7,[pipe_consistency_linter] Use the |> pipe operator instead of the %>% pipe operator.
select("PARAM", "LBSTRESC", loq_flag_var)
select("PARAM", "LBSTRESC", all_of(loq_flag_var))

yaxis_param_loqs_data <- data %>%
mutate(
PARAM = !!sym(t_param_var_y), LBSTRESC = !!sym(t_lbstresc_var_y),
sym(loq_flag_var) == !!sym(loq_flag_var)
) %>%
select("PARAM", "LBSTRESC", loq_flag_var)
select("PARAM", "LBSTRESC", all_of(loq_flag_var))

# add footnote to identify xaxis assay LLOQ and ULOQ values pulled from data
caption_loqs_label_x <- h_caption_loqs_label(loqs_data = xaxis_param_loqs_data, flag_var = loq_flag_var)
Expand Down Expand Up @@ -345,24 +345,26 @@
stats::cor(!!sym(yvar), !!sym(xvar), method = "spearman", use = "complete.obs"),
NA
))
# To avoid Note: no visible binding for global variable
corr <- intercept <- NULL
plot1 <- plot1 +
ggplot2::geom_abline(
data = filter(sub_data, row_number() == 1), # only need to return 1 row within group_by
ggplot2::aes(intercept = .data$intercept, slope = .data$slope, color = !!sym(trt_group))
) +
ggplot2::geom_text(
data = filter(sub_data, row_number() == 1),
ggplot2::aes_(
ggplot2::aes(
x = -Inf,
y = Inf,
hjust = 0,
vjust = 1,
label = ~ ifelse(
label = ifelse(
!is.na(intercept) & !is.na(slope) & !is.na(corr),
sprintf("y = %.2f+%.2fX\ncor = %.2f", intercept, slope, corr),
paste0("Insufficient Data For Regression")
"Insufficient Data For Regression"
),
color = sym(trt_group)
color = !!trt_group
),
size = reg_text_size,
show.legend = FALSE
Expand Down
2 changes: 1 addition & 1 deletion R/g_lineplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,6 @@ unique_name <- function(newname, old_names) {
}

gg_color_hue <- function(n) {
hues <- seq(15, 375, length = n + 1)
hues <- seq(15, 375, length.out = n + 1)
grDevices::hcl(h = hues, l = 65, c = 100)[1:n]
}
16 changes: 1 addition & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

Longitudinal biomarker/lab visualizations functions. These can be used stand alone but are also called by the
[teal.goshawk](https://insightsengineering.github.io/teal.goshawk/) package which provides modules to be used
inside [`teal`](https://insightsengineering.github.io/teal/) applications.
inside [`teal`](https://pharmaverse.github.io/teal/) applications.

## Functions
<!-- markdownlint-disable MD007 MD030 -->
Expand All @@ -43,17 +43,3 @@ pak::pkg_install("insightsengineering/goshawk@*release")
# install.packages("pak")
pak::pkg_install("insightsengineering/goshawk")
```

## Stargazers and Forkers

### Stargazers over time

[![Stargazers over time](https://starchart.cc/insightsengineering/goshawk.svg)](https://starchart.cc/insightsengineering/goshawk)

### Stargazers

[![Stargazers repo roster for @insightsengineering/goshawk](https://reporoster.com/stars/insightsengineering/goshawk)](https://github.com/insightsengineering/goshawk/stargazers)

### Forkers

[![Forkers repo roster for @insightsengineering/goshawk](https://reporoster.com/forks/insightsengineering/goshawk)](https://github.com/insightsengineering/goshawk/network/members)
2 changes: 1 addition & 1 deletion man/g_boxplot.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/g_correlationplot.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/g_lineplot.Rd

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

1 change: 1 addition & 0 deletions man/goshawk-package.Rd

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

6 changes: 6 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# testthat is a suggested package: only run the tests when it is available.
if (requireNamespace("testthat", quietly = TRUE)) {
library(testthat)
library(goshawk)
test_check("goshawk")
}
91 changes: 91 additions & 0 deletions tests/testthat/helper-data.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# Deterministic, self-contained lab data (ADaM-like) used by all tests.
# 12 subjects (4 per arm), 3 visits, 2 parameters (CRP, ALT).
make_adlb <- function() {
arms <- c("A: Drug X", "B: Placebo", "C: Combination")
subj <- data.frame(
USUBJID = sprintf("S-%02d", 1:12),
ARM = rep(arms, each = 4),
SEX = rep(c("F", "M"), 6),
stringsAsFactors = FALSE
)
visits <- data.frame(
AVISITCD = c("BL", "W 1", "W 5"),
AVISITCDN = c(0, 1, 5),
stringsAsFactors = FALSE
)
params <- data.frame(
PARAMCD = c("CRP", "ALT"),
PARAM = c("C-reactive protein", "Alanine transaminase"),
AVALU = c("mg/L", "U/L"),
ANRLO = c(0.5, 20),
ANRHI = c(1.5, 60),
stringsAsFactors = FALSE
)
dat <- merge(merge(subj, visits, by = NULL), params, by = NULL)
dat <- dat[order(dat$PARAMCD, dat$USUBJID, dat$AVISITCDN), ]
rownames(dat) <- NULL

idx <- seq_len(nrow(dat))
scale_p <- ifelse(dat$PARAMCD == "CRP", 1, 40)
dat$AVAL <- round(scale_p * (0.6 + 0.05 * (idx %% 7) + 0.1 * dat$AVISITCDN + 0.02 * sin(idx)), 3)
dat$BASE <- round(scale_p * (0.7 + 0.04 * (idx %% 5) + 0.03 * cos(idx)), 3)
dat$STUDYID <- "STUDY-1"
dat$ARMCD <- c("A", "B", "C")[match(dat$ARM, arms)]
dat$TRTORD <- match(dat$ARM, arms)
dat$LBSTRESC <- as.character(dat$AVAL)
dat$LOQFL <- "N"

# one lower and one upper limit of quantification per parameter
lloq <- dat$USUBJID == "S-01" & dat$AVISITCD == "BL"
uloq <- dat$USUBJID == "S-02" & dat$AVISITCD == "W 1"
dat$LBSTRESC[lloq & dat$PARAMCD == "CRP"] <- "< 0.5"
dat$LBSTRESC[uloq & dat$PARAMCD == "CRP"] <- "> 1.5"
dat$LBSTRESC[lloq & dat$PARAMCD == "ALT"] <- "< 20"
dat$LBSTRESC[uloq & dat$PARAMCD == "ALT"] <- "> 60"
dat$LOQFL[lloq | uloq] <- "Y"

# one missing CRP result: S-03 at W 5
dat$AVAL[dat$USUBJID == "S-03" & dat$AVISITCD == "W 5" & dat$PARAMCD == "CRP"] <- NA_real_

dat$ARM <- factor(dat$ARM, levels = arms)
attr(dat$ARM, "label") <- "Description of Planned Arm"
dat$SEX <- factor(dat$SEX)
attr(dat$ANRLO, "label") <- "Analysis Normal Range Lower Limit"
attr(dat$ANRHI, "label") <- "Analysis Normal Range Upper Limit"

loqs <- goshawk:::h_identify_loq_values(dat, "LOQFL")
dat <- merge(dat, loqs, by = "PARAM", sort = FALSE)
dat <- dat[order(dat$PARAMCD, dat$USUBJID, dat$AVISITCDN), ]
rownames(dat) <- NULL
dat
}

arm_colors <- c(
"A: Drug X" = "#000000",
"B: Placebo" = "#3498DB",
"C: Combination" = "#E74C3C"
)

# Wide-format data for g_correlationplot: one row per subject and visit.
make_corr_data <- function() {
adlb <- make_adlb()
crp <- adlb[adlb$PARAMCD == "CRP", ]
alt <- adlb[adlb$PARAMCD == "ALT", ]
key <- c("USUBJID", "AVISITCD")
dat <- merge(
crp[, c(key, "ARM", "AVAL", "LBSTRESC", "PARAM", "LOQFL", "ANRHI", "ANRLO", "ULOQN", "LLOQN")],
alt[, c(key, "BASE", "LBSTRESC", "PARAM", "LOQFL", "ANRHI", "ANRLO", "ULOQN", "LLOQN")],
by = key,
suffixes = c(".CRP", ".ALT")
)
names(dat)[names(dat) == "LBSTRESC.CRP"] <- "LBSTRESC_CRP"
names(dat)[names(dat) == "LBSTRESC.ALT"] <- "LBSTRESC_ALT"
names(dat)[names(dat) == "PARAM.CRP"] <- "PARAM_CRP"
names(dat)[names(dat) == "PARAM.ALT"] <- "PARAM_ALT"
dat$LOQFL_COMB <- ifelse(dat$LOQFL.CRP == "Y" | dat$LOQFL.ALT == "Y", "Y", "N")
dat <- dat[!is.na(dat$AVAL) & !is.na(dat$BASE), ]
dat$ARM <- factor(dat$ARM, levels = levels(adlb$ARM))
attr(dat$ARM, "label") <- "Description of Planned Arm"
rownames(dat) <- NULL
dat
}
Loading
Loading