Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closes #2513 accept_ms: accept ms as input unit for derive_param_qtc() #2550

Merged
merged 15 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@

## Updates of Existing Functions

- The `derive_param_qtc()` function accepts now both `"msec"` and `"ms"` as unit
yurovska marked this conversation as resolved.
Show resolved Hide resolved
of the input parameters. (#2513)

## Breaking Changes

- The following function arguments are entering the next phase of the deprecation process: (#2487)
Expand Down
99 changes: 52 additions & 47 deletions R/derive_adeg_params.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#'
#' The variable specified by `by_vars` and `PARAMCD` must be a unique key of
#' the input dataset after restricting it by the filter condition (`filter`
#' parameter) and to the parameters specified by `qt_code` and `rr_code`.
#' argument) and to the parameters specified by `qt_code` and `rr_code`.
#'
#'
#' @param by_vars Grouping variables
Expand All @@ -24,59 +24,62 @@
#'
#' @param method Method used to QT correction
#'
#' Permitted Values: `"Bazett"`, `"Fridericia"`, `"Sagie"`
#' See [compute_qtc()] for details.
#'
#' *Permitted Values*: `"Bazett"`, `"Fridericia"`, `"Sagie"`
#'
#' @param qt_code QT parameter code
#'
#' The observations where `PARAMCD` equals the specified value are considered
#' as the QT interval assessments. It is expected that QT is measured in msec.
#' as the QT interval assessments. It is expected that QT is measured in msec
#' or ms.
yurovska marked this conversation as resolved.
Show resolved Hide resolved
#'
#' Permitted Values: character value
#' *Permitted Values*: character value
#'
#' @param rr_code RR parameter code
#'
#' The observations where `PARAMCD` equals the specified value are considered
#' as the RR interval assessments. It is expected that RR is measured in msec.
#' as the RR interval assessments. It is expected that RR is measured in msec
#' or ms.
yurovska marked this conversation as resolved.
Show resolved Hide resolved
#'
#' Permitted Values: character value
#' *Permitted Values*: character value
#'
#' @param get_unit_expr An expression providing the unit of the parameter
#'
#' The result is used to check the units of the input parameters.
#'
#' Permitted Values: A variable of the input dataset or a function call
#' *Permitted Values*: An expression which is evaluable in the input dataset
#' and results in a character value
#'
#' @inheritParams derive_param_map
#'
#' @inheritParams derive_param_computed
#'
#' @seealso [compute_qtc()]
#'
#' @return The input dataset with the new parameter added. Note, a variable will only
#' be populated in the new parameter rows if it is specified in `by_vars`.
#'
#' @seealso [compute_qtc()]
#'
#' @family der_prm_bds_findings
#'
#' @keywords der_prm_bds_findings
#'
#' @export
#'
#' @seealso [compute_qtc()]
#'
#' @examples
#' library(tibble)
#'
#' adeg <- tribble(
#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT,
#' "01-701-1015", "HR", "Heart Rate (beats/min)", 70.14, "beats/min", "BASELINE",
#' "01-701-1015", "QT", "QT Duration (msec)", 370, "msec", "WEEK 2",
#' "01-701-1015", "HR", "Heart Rate (beats/min)", 62.66, "beats/min", "WEEK 1",
#' "01-701-1015", "RR", "RR Duration (msec)", 710, "msec", "WEEK 2",
#' "01-701-1028", "HR", "Heart Rate (beats/min)", 85.45, "beats/min", "BASELINE",
#' "01-701-1028", "QT", "QT Duration (msec)", 480, "msec", "WEEK 2",
#' "01-701-1028", "QT", "QT Duration (msec)", 350, "msec", "WEEK 3",
#' "01-701-1028", "HR", "Heart Rate (beats/min)", 56.54, "beats/min", "WEEK 3",
#' "01-701-1028", "RR", "RR Duration (msec)", 842, "msec", "WEEK 2",
#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT,
#' "01-701-1015", "HR", "Heart Rate (beats/min)", 70.14, "beats/min", "BASELINE",
#' "01-701-1015", "QT", "QT Duration (ms)", 370, "ms", "WEEK 2",
#' "01-701-1015", "HR", "Heart Rate (beats/min)", 62.66, "beats/min", "WEEK 1",
#' "01-701-1015", "RR", "RR Duration (ms)", 710, "ms", "WEEK 2",
#' "01-701-1028", "HR", "Heart Rate (beats/min)", 85.45, "beats/min", "BASELINE",
#' "01-701-1028", "QT", "QT Duration (ms)", 480, "ms", "WEEK 2",
#' "01-701-1028", "QT", "QT Duration (ms)", 350, "ms", "WEEK 3",
#' "01-701-1028", "HR", "Heart Rate (beats/min)", 56.54, "beats/min", "WEEK 3",
#' "01-701-1028", "RR", "RR Duration (ms)", 842, "ms", "WEEK 2"
#' )
#'
#' derive_param_qtc(
Expand All @@ -85,8 +88,8 @@
#' method = "Bazett",
#' set_values_to = exprs(
#' PARAMCD = "QTCBR",
#' PARAM = "QTcB - Bazett's Correction Formula Rederived (msec)",
#' AVALU = "msec"
#' PARAM = "QTcB - Bazett's Correction Formula Rederived (ms)",
#' AVALU = "ms"
#' ),
#' get_unit_expr = AVALU
#' )
Expand All @@ -97,8 +100,8 @@
#' method = "Fridericia",
#' set_values_to = exprs(
#' PARAMCD = "QTCFR",
#' PARAM = "QTcF - Fridericia's Correction Formula Rederived (msec)",
#' AVALU = "msec"
#' PARAM = "QTcF - Fridericia's Correction Formula Rederived (ms)",
#' AVALU = "ms"
#' ),
#' get_unit_expr = extract_unit(PARAM)
#' )
Expand All @@ -109,8 +112,8 @@
#' method = "Sagie",
#' set_values_to = exprs(
#' PARAMCD = "QTLCR",
#' PARAM = "QTlc - Sagie's Correction Formula Rederived (msec)",
#' AVALU = "msec"
#' PARAM = "QTlc - Sagie's Correction Formula Rederived (ms)",
#' AVALU = "ms"
#' ),
#' get_unit_expr = extract_unit(PARAM)
#' )
Expand Down Expand Up @@ -138,13 +141,13 @@ derive_param_qtc <- function(dataset,
assert_unit(
dataset,
param = qt_code,
required_unit = "msec",
required_unit = c("msec", "ms"),
get_unit_expr = !!get_unit_expr
)
assert_unit(
dataset,
param = rr_code,
required_unit = "msec",
required_unit = c("msec", "ms"),
get_unit_expr = !!get_unit_expr
)

Expand All @@ -168,13 +171,12 @@ derive_param_qtc <- function(dataset,
#'
#' @param method Method used to QT correction
#'
#' Permitted Values: `"Bazett"`, `"Fridericia"`, `"Sagie"`
#' *Permitted Values*: `"Bazett"`, `"Fridericia"`, `"Sagie"`
#'
#' @return
#' `"QTCBR"` if `method` is `"Bazett"`, `"QTCFR"` if it's `"Fridericia"` or
#' `"QTLCR"` if it's `"Sagie"`. An error otherwise.
#'
#'
#' @export
#'
#' @family der_prm_bds_findings
Expand All @@ -196,16 +198,19 @@ default_qtc_paramcd <- function(method) {
#'
#' @param qt QT interval
#'
#' A numeric vector is expected. It is expected that QT is measured in msec.
#' A numeric vector is expected. It is expected that QT is measured in msec or
#' ms.
yurovska marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @param rr RR interval
#'
#' A numeric vector is expected. It is expected that RR is measured in msec.
#' A numeric vector is expected. It is expected that RR is measured in msec or
#' ms.
yurovska marked this conversation as resolved.
Show resolved Hide resolved
#'
#' @inheritParams derive_param_qtc
#' @param method Method used to QT correction
#'
#' *Permitted Values*: `"Bazett"`, `"Fridericia"`, `"Sagie"`
#'
#' @return QT interval in msec
#' @return QT interval in ms
#'
#' @details
#' Depending on the chosen `method` one of the following formulae is used.
Expand All @@ -228,11 +233,11 @@ default_qtc_paramcd <- function(method) {
#' @seealso [derive_param_qtc()]
#'
#' @examples
#' compute_qtc(qt = 350, rr = 56.54, method = "Bazett")
#' compute_qtc(qt = 350, rr = 857, method = "Bazett")
#'
#' compute_qtc(qt = 350, rr = 56.54, method = "Fridericia")
#' compute_qtc(qt = 350, rr = 857, method = "Fridericia")
#'
#' compute_qtc(qt = 350, rr = 56.54, method = "Sagie")
#' compute_qtc(qt = 350, rr = 857, method = "Sagie")
compute_qtc <- function(qt, rr, method) {
assert_numeric_vector(qt)
assert_numeric_vector(rr)
Expand Down Expand Up @@ -262,7 +267,7 @@ compute_qtc <- function(qt, rr, method) {
#'
#' The variable specified by `by_vars` and `PARAMCD` must be a unique key of
#' the input dataset after restricting it by the filter condition (`filter`
#' parameter) and to the parameters specified by `hr_code`.
#' argument) and to the parameters specified by `hr_code`.
#'
#' @param hr_code HR parameter code
#'
Expand Down Expand Up @@ -294,23 +299,23 @@ compute_qtc <- function(qt, rr, method) {
#' adeg <- tribble(
#' ~USUBJID, ~PARAMCD, ~PARAM, ~AVAL, ~AVALU, ~VISIT,
#' "01-701-1015", "HR", "Heart Rate", 70.14, "beats/min", "BASELINE",
#' "01-701-1015", "QT", "QT Duration", 370, "msec", "WEEK 2",
#' "01-701-1015", "QT", "QT Duration", 370, "ms", "WEEK 2",
#' "01-701-1015", "HR", "Heart Rate", 62.66, "beats/min", "WEEK 1",
#' "01-701-1015", "RR", "RR Duration", 710, "msec", "WEEK 2",
#' "01-701-1015", "RR", "RR Duration", 710, "ms", "WEEK 2",
#' "01-701-1028", "HR", "Heart Rate", 85.45, "beats/min", "BASELINE",
#' "01-701-1028", "QT", "QT Duration", 480, "msec", "WEEK 2",
#' "01-701-1028", "QT", "QT Duration", 350, "msec", "WEEK 3",
#' "01-701-1028", "QT", "QT Duration", 480, "ms", "WEEK 2",
#' "01-701-1028", "QT", "QT Duration", 350, "ms", "WEEK 3",
#' "01-701-1028", "HR", "Heart Rate", 56.54, "beats/min", "WEEK 3",
#' "01-701-1028", "RR", "RR Duration", 842, "msec", "WEEK 2"
#' "01-701-1028", "RR", "RR Duration", 842, "ms", "WEEK 2"
#' )
#'
#' derive_param_rr(
#' adeg,
#' by_vars = exprs(USUBJID, VISIT),
#' set_values_to = exprs(
#' PARAMCD = "RRR",
#' PARAM = "RR Duration Rederived (msec)",
#' AVALU = "msec"
#' PARAM = "RR Duration Rederived (ms)",
#' AVALU = "ms"
#' ),
#' get_unit_expr = AVALU
#' )
Expand Down Expand Up @@ -362,7 +367,7 @@ derive_param_rr <- function(dataset,
#'
#' @details Usually this computation function can not be used with `%>%`.
#'
#' @return RR interval in msec:
#' @return RR interval in ms:
#' \deqn{\frac{60000}{HR}}{60000 / HR}
#'
#' @family com_bds_findings
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
url: https://pharmaverse.github.io/admiral

template:
math-rendering: mathjax
bootstrap: 5
params:
bootswatch: flatly
Expand Down
36 changes: 18 additions & 18 deletions inst/templates/ad_adeg.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ eg <- convert_blanks_to_na(eg)

# Assign PARAMCD, PARAM, and PARAMN
param_lookup <- tibble::tribble(
~EGTESTCD, ~PARAMCD, ~PARAM, ~PARAMN,
"ECGINT", "EGINTP", "ECG Interpretation", 1,
"HR", "HR", "Heart Rate (beats/min)", 2,
"RR", "RR", "RR Duration (msec)", 3,
"RRR", "RRR", "RR Duration Rederived (msec)", 4,
"QT", "QT", "QT Duration (msec)", 10,
"QTCBR", "QTCBR", "QTcB - Bazett's Correction Formula Rederived (msec)", 11,
"QTCFR", "QTCFR", "QTcF - Fridericia's Correction Formula Rederived (msec)", 12,
"QTLCR", "QTLCR", "QTlc - Sagie's Correction Formula Rederived (msec)", 13,
~EGTESTCD, ~PARAMCD, ~PARAM, ~PARAMN,
"ECGINT", "EGINTP", "ECG Interpretation", 1,
"HR", "HR", "Heart Rate (beats/min)", 2,
"RR", "RR", "RR Duration (ms)", 3,
"RRR", "RRR", "RR Duration Rederived (ms)", 4,
"QT", "QT", "QT Duration (ms)", 10,
"QTCBR", "QTCBR", "QTcB - Bazett's Correction Formula Rederived (ms)", 11,
"QTCFR", "QTCFR", "QTcF - Fridericia's Correction Formula Rederived (ms)", 12,
"QTLCR", "QTLCR", "QTlc - Sagie's Correction Formula Rederived (ms)", 13,
)

range_lookup <- tibble::tribble(
Expand All @@ -56,18 +56,18 @@ range_lookup <- tibble::tribble(

# Assign AVALCAx
avalcax_lookup <- exprs(
~condition, ~AVALCAT1, ~AVALCA1N,
startsWith(PARAMCD, "QT") & AVAL <= 450, "<= 450 msec", 1,
startsWith(PARAMCD, "QT") & AVAL > 450 & AVAL <= 480, ">450<=480 msec", 2,
startsWith(PARAMCD, "QT") & AVAL > 480 & AVAL <= 500, ">480<=500 msec", 3,
startsWith(PARAMCD, "QT") & AVAL > 500, ">500 msec", 4
~condition, ~AVALCAT1, ~AVALCA1N,
startsWith(PARAMCD, "QT") & AVAL <= 450, "<= 450 ms", 1,
startsWith(PARAMCD, "QT") & AVAL > 450 & AVAL <= 480, ">450<=480 ms", 2,
startsWith(PARAMCD, "QT") & AVAL > 480 & AVAL <= 500, ">480<=500 ms", 3,
startsWith(PARAMCD, "QT") & AVAL > 500, ">500 ms", 4
)
# Assign CHGCAx
chgcax_lookup <- exprs(
~condition, ~CHGCAT1, ~CHGCAT1N,
startsWith(PARAMCD, "QT") & CHG <= 30, "<= 30 msec", 1,
startsWith(PARAMCD, "QT") & CHG > 30 & CHG <= 60, ">30<=60 msec", 2,
startsWith(PARAMCD, "QT") & CHG > 60, ">60 msec", 3
~condition, ~CHGCAT1, ~CHGCAT1N,
startsWith(PARAMCD, "QT") & CHG <= 30, "<= 30 ms", 1,
startsWith(PARAMCD, "QT") & CHG > 30 & CHG <= 60, ">30<=60 ms", 2,
startsWith(PARAMCD, "QT") & CHG > 60, ">60 ms", 3
)

# Derivations ----
Expand Down
16 changes: 9 additions & 7 deletions man/compute_qtc.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/compute_rr.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/default_qtc_paramcd.Rd

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

3 changes: 2 additions & 1 deletion man/derive_param_bmi.Rd

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

3 changes: 2 additions & 1 deletion man/derive_param_bsa.Rd

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

Loading
Loading