Skip to content

Commit

Permalink
Merge branch 'main' into propagation-march-2024
Browse files Browse the repository at this point in the history
  • Loading branch information
walkowif authored Apr 18, 2024
2 parents 9306a1c + b174c12 commit 2017f55
Show file tree
Hide file tree
Showing 25 changed files with 72 additions and 60 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ default_language_version:
python: python3
repos:
- repo: https://github.com/lorenzwalthert/precommit
rev: v0.4.0
rev: v0.4.2
hooks:
- id: style-files
name: Style code with `styler`
Expand Down
8 changes: 6 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Type: Package
Package: random.cdisc.data
Title: Create Random ADaM Datasets
Version: 0.3.15.9000
Date: 2024-03-28
Version: 0.3.15.9002
Date: 2024-04-16
Authors@R: c(
person("Pawel", "Rucki", , "[email protected]", role = "aut"),
person("Nick", "Paszty", , "[email protected]", role = "aut"),
Expand All @@ -19,6 +19,10 @@ Description: A set of functions to create random Analysis Data Model
described by the Clinical Data Interchange Standards Consortium
(CDISC) Analysis Data Model Team.
License: Apache License 2.0
URL: https://insightsengineering.github.io/random.cdisc.data/,
https://github.com/insightsengineering/random.cdisc.data/
BugReports:
https://github.com/insightsengineering/random.cdisc.data/issues
Depends:
R (>= 3.6)
Imports:
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export(replace_na)
export(rtexp)
export(rtpois)
export(sample_fct)
export(var_relabel)
export(visit_schedule)
import(dplyr)
importFrom(lifecycle,badge)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# random.cdisc.data 0.3.15.9000
# random.cdisc.data 0.3.15.9002

### Miscellaneous
* Renamed `var_relabel` into `rcd_var_relabel` and copied new functionalities to avoid namespace conflict with `formatters` package.
* Made `rcd_var_relabel` internal as it was intended for developers use only.

# random.cdisc.data 0.3.15

Expand Down
2 changes: 1 addition & 1 deletion R/radae.R
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ radae <- function(adsl,
AETOXGR %in% c(4, 5) ~ "SEVERE"
))

adae <- var_relabel(
adae <- rcd_var_relabel(
adae,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
4 changes: 2 additions & 2 deletions R/radaette.R
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,12 @@ radaette <- function(adsl,
dplyr::bind_rows(patient_data, ae_data)
}) %>%
Reduce(rbind, .) %>%
var_relabel(
rcd_var_relabel(
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
)

adaette <- var_relabel(
adaette <- rcd_var_relabel(
adaette,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
2 changes: 1 addition & 1 deletion R/radcm.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ radcm <- function(adsl,
`[`(c(4, 5, 1, 2, 3)) %>%
dplyr::mutate(CMCAT = CMCLAS)

adcm <- var_relabel(
adcm <- rcd_var_relabel(
adcm,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
2 changes: 1 addition & 1 deletion R/raddv.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ raddv <- function(adsl,
Reduce(rbind, .) %>%
dplyr::mutate(DVSCAT = DVCAT)

addv <- var_relabel(
addv <- rcd_var_relabel(
addv,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
8 changes: 2 additions & 6 deletions R/radeg.R
Original file line number Diff line number Diff line change
Expand Up @@ -167,16 +167,12 @@ radeg <- function(adsl,
dplyr::mutate(BNRIND = ANRIND[ABLFL == "Y"]) %>%
dplyr::ungroup() %>%
dplyr::mutate(ATPTN = 1) %>%
dplyr::mutate(DTYPE = NA) %>%
var_relabel(
STUDYID = attr(adeg$STUDYID, "label"),
USUBJID = attr(adeg$USUBJID, "label")
)
dplyr::mutate(DTYPE = NA)

adeg$ANRIND <- factor(adeg$ANRIND, levels = c("LOW", "NORMAL", "HIGH"))
adeg$BNRIND <- factor(adeg$BNRIND, levels = c("LOW", "NORMAL", "HIGH"))

adeg <- var_relabel(
adeg <- rcd_var_relabel(
adeg,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
2 changes: 1 addition & 1 deletion R/radex.R
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ radex <- function(adsl,
AVAL
))

adex <- var_relabel(
adex <- rcd_var_relabel(
adex,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
2 changes: 1 addition & 1 deletion R/radhy.R
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ radhy <- function(adsl,
dplyr::ungroup()

adhy <- adhy %>%
var_relabel(
rcd_var_relabel(
STUDYID = attr(adsl$STUDYID, "label"),
USUBJID = attr(adsl$USUBJID, "label")
)
Expand Down
4 changes: 2 additions & 2 deletions R/radlb.R
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ radlb <- function(adsl,
ATOXGR == "-3" ~ "<Missing>",
ATOXGR == "-4" ~ "<Missing>",
))) %>%
var_relabel(
rcd_var_relabel(
STUDYID = attr(adsl$STUDYID, "label"),
USUBJID = attr(adsl$USUBJID, "label")
)
Expand Down Expand Up @@ -294,7 +294,7 @@ radlb <- function(adsl,
# merge grade_lookup onto adlb
adlb <- dplyr::left_join(adlb, grade_lookup, by = "PARAMCD")

adlb <- var_relabel(
adlb <- rcd_var_relabel(
adlb,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
2 changes: 1 addition & 1 deletion R/radmh.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ radmh <- function(adsl,
`[`(c(4, 5, 1, 2, 3)) %>%
dplyr::mutate(MHTERM = MHDECOD)

admh <- var_relabel(
admh <- rcd_var_relabel(
admh,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
4 changes: 2 additions & 2 deletions R/radqlqc.R
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,14 @@ radqlqc <- function(adsl,
dplyr::mutate(PCHG2 = 100 * (CHG2 / BASE2)) %>%
dplyr::mutate(CHG = AVAL - BASE) %>%
dplyr::mutate(PCHG = 100 * (CHG / BASE)) %>%
var_relabel(
rcd_var_relabel(
STUDYID = attr(adsl$STUDYID, "label"),
USUBJID = attr(adsl$USUBJID, "label")
)
# derive CHGCAT1 ----------------------------------------------------------
adqlqc_tmp <- derv_chgcat1(dataset = adqlqc_tmp)

adqlqc_tmp <- var_relabel(
adqlqc_tmp <- rcd_var_relabel(
adqlqc_tmp,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
4 changes: 2 additions & 2 deletions R/radqs.R
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,12 @@ radqs <- function(adsl,
dplyr::mutate(PCHG2 = 100 * (CHG2 / BASE2)) %>%
dplyr::mutate(CHG = AVAL - BASE) %>%
dplyr::mutate(PCHG = 100 * (CHG / BASE)) %>%
var_relabel(
rcd_var_relabel(
STUDYID = attr(adsl$STUDYID, "label"),
USUBJID = attr(adsl$USUBJID, "label")
)

adqs <- var_relabel(
adqs <- rcd_var_relabel(
adqs,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
4 changes: 2 additions & 2 deletions R/radrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,12 @@ radrs <- function(adsl,
}) %>%
Reduce(rbind, .) %>%
dplyr::mutate(AVALC = factor(AVALC, levels = names(param_codes))) %>%
var_relabel(
rcd_var_relabel(
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
)

adrs <- var_relabel(
adrs <- rcd_var_relabel(
adrs,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
2 changes: 1 addition & 1 deletion R/radsub.R
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ radsub <- function(adsl,

adsub <- adsub[order(adsub$STUDYID, adsub$USUBJID, adsub$PARAMCD), ]

adsub <- var_relabel(
adsub <- rcd_var_relabel(
adsub,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
4 changes: 2 additions & 2 deletions R/radtte.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ radtte <- function(adsl,
dplyr::select(-"LAMBDA", -"CNSR_P")
}) %>%
Reduce(rbind, .) %>%
var_relabel(
rcd_var_relabel(
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier" # )
)
Expand Down Expand Up @@ -202,7 +202,7 @@ radtte <- function(adsl,
adtte <- do.call("rbind", adtte_lst)
rownames(adtte) <- NULL

adtte <- var_relabel(
adtte <- rcd_var_relabel(
adtte,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
4 changes: 2 additions & 2 deletions R/radvs.R
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ radvs <- function(adsl,
dplyr::ungroup() %>%
dplyr::mutate(ATPTN = 1) %>%
dplyr::mutate(DTYPE = NA) %>%
var_relabel(
rcd_var_relabel(
USUBJID = attr(adsl$USUBJID, "label"),
STUDYID = attr(adsl$STUDYID, "label")
)

advs <- var_relabel(
advs <- rcd_var_relabel(
advs,
STUDYID = "Study Identifier",
USUBJID = "Unique Subject Identifier"
Expand Down
28 changes: 16 additions & 12 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -180,28 +180,32 @@ retain <- function(df, value_var, event, outside = NA) {

#' Primary Keys: Labels
#'
#' Relabel a subset of variables in a data set.
#' @description Shallow copy of `formatters::var_relabel()`. Used mainly internally to
#' relabel a subset of variables in a data set.
#'
#' @param x (`data.frame`)\cr Data frame containing variables to which labels are applied.
#' @param ... (`named character`)\cr Name-Value pairs, where name corresponds to a variable
#' name in `x` and the value to the new variable label.
#' name in `x` and the value to the new variable label.
#' @return x (`data.frame`)\cr Data frame with labels applied.
#'
#' @export
#'
#' @examples
#' adsl <- radsl()
#' var_relabel(adsl,
#' STUDYID = "Study Identifier",
#' USUBJID = "Unique Subject Identifier"
#' )
var_relabel <- function(x, ...) {
#' @keywords internal
rcd_var_relabel <- function(x, ...) {
stopifnot(is.data.frame(x))
if (missing(...)) {
return(x)
}
dots <- list(...)
varnames <- names(dots)
if (is.null(varnames)) {
stop("missing variable declarations")
}
map_varnames <- match(varnames, names(x))
map_varnames <- match(varnames, colnames(x))
if (any(is.na(map_varnames))) {
stop("variables: ", paste(varnames[is.na(map_varnames)], collapse = ", "), " not found")
}
if (any(vapply(dots, Negate(is.character), logical(1)))) {
stop("all variable labels must be of type character")
}
for (i in seq_along(map_varnames)) {
attr(x[[map_varnames[[i]]]], "label") <- dots[[i]]
}
Expand Down
2 changes: 1 addition & 1 deletion _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ reference:
- rtexp
- rtpois
- sample_fct
- var_relabel
- rcd_var_relabel
- visit_schedule
9 changes: 9 additions & 0 deletions man/random.cdisc.data-package.Rd

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

17 changes: 6 additions & 11 deletions man/var_relabel.Rd → man/rcd_var_relabel.Rd

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

1 change: 1 addition & 0 deletions random.cdisc.data.Rproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ AutoAppendNewline: Yes
StripTrailingWhitespace: Yes

BuildType: Package
PackageUseDevtools: Yes
PackageInstallArgs: --no-multiarch --with-keep.source
PackageRoxygenize: rd,collate,namespace
8 changes: 4 additions & 4 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ test_that("retain works as expected", {
expect_equal(result, expected)
})

test_that("var_relabel works as expected", {
result <- random.cdisc.data:::var_relabel(
test_that("rcd_var_relabel works as expected", {
result <- rcd_var_relabel(
data.frame(letters = letters[1:5]),
letters = "Letter Variable"
)
expect_identical(attr(result$letters, "label"), "Letter Variable")
})

test_that("var_relabel returns correct error message", {
test_that("rcd_var_relabel returns correct error message", {
expect_error(
random.cdisc.data:::var_relabel(
rcd_var_relabel(
data.frame(letters = letters[1:5]),
"Letter Variable"
), "missing variable declarations"
Expand Down

0 comments on commit 2017f55

Please sign in to comment.