Skip to content

Commit

Permalink
Move custom formatting functions to tern
Browse files Browse the repository at this point in the history
  • Loading branch information
edelarua committed Sep 22, 2023
1 parent dd6d295 commit bc5ee98
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 60 deletions.
22 changes: 2 additions & 20 deletions book/tables/pharmacokinetic/pkpt02.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ library(tern)
adpp <- synthetic_cdisc_dataset("latest", "adpp")
adpp <- adpp %>% filter(PPSPEC == "Plasma", AVISIT == "CYCLE 1 DAY 1")
fmt_sigfig_mean_sd <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
num <- gsub("\\.$", "", formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#"))
paste0(num[1], " (", num[2], ")")
}
}
fmt_sigfig_range <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
num <- gsub("\\.$", "", formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#"))
paste0(num[1], " - ", num[2])
}
}
```

## Standard Table -- Plasma
Expand All @@ -60,12 +42,12 @@ lyt <- basic_table() %>%
.stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"),
.formats = c(
n = "xx.",
mean_sd = fmt_sigfig_mean_sd(3),
mean_sd = format_sigfig(3, "value_paren"),
cv = "xx.x",
geom_mean = format_sigfig(3),
geom_cv = "xx.x",
median = format_sigfig(3),
range = fmt_sigfig_range(3)
range = format_sigfig(3, "range")
)
)
```
Expand Down
22 changes: 2 additions & 20 deletions book/tables/pharmacokinetic/pkpt04.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,6 @@ library(tern)
adpp <- synthetic_cdisc_dataset("latest", "adpp")
adpp <- adpp %>% filter(PPSPEC == "Urine", AVISIT == "CYCLE 1 DAY 1")
fmt_sigfig_mean_sd <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
num <- gsub("\\.$", "", formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#"))
paste0(num[1], " (", num[2], ")")
}
}
fmt_sigfig_range <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
num <- gsub("\\.$", "", formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#"))
paste0(num[1], " - ", num[2])
}
}
```

## Standard Table
Expand All @@ -60,12 +42,12 @@ lyt <- basic_table() %>%
.stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"),
.formats = c(
n = "xx.",
mean_sd = fmt_sigfig_mean_sd(3),
mean_sd = format_sigfig(3, "value_paren"),
cv = "xx.x",
geom_mean = format_sigfig(3),
geom_cv = "xx.x",
median = format_sigfig(3),
range = fmt_sigfig_range(3)
range = format_sigfig(3, "range")
)
)
```
Expand Down
22 changes: 2 additions & 20 deletions book/tables/pharmacokinetic/pkpt06.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,6 @@ library(stringr)
adpp <- synthetic_cdisc_dataset("latest", "adpp")
adpp <- adpp %>% filter(AVISIT == "CYCLE 1 DAY 1", str_detect(tolower(PARAM), regex("norm by dose", ignore_case = TRUE)))
fmt_sigfig_mean_sd <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
num <- gsub("\\.$", "", formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#"))
paste0(num[1], " (", num[2], ")")
}
}
fmt_sigfig_range <- function(sigfig) {
checkmate::assert_integerish(sigfig)
function(x, ...) {
if (!is.numeric(x)) stop("`format_sigfig` cannot be used for non-numeric values. Please choose another format.")
num <- gsub("\\.$", "", formatC(signif(x, digits = sigfig), digits = sigfig, format = "fg", flag = "#"))
paste0(num[1], " - ", num[2])
}
}
```

## Standard Table
Expand All @@ -61,12 +43,12 @@ lyt <- basic_table() %>%
.stats = c("n", "mean_sd", "cv", "geom_mean", "geom_cv", "median", "range"),
.formats = c(
n = "xx.",
mean_sd = fmt_sigfig_mean_sd(3),
mean_sd = format_sigfig(3, "value_paren"),
cv = "xx.x",
geom_mean = format_sigfig(3),
geom_cv = "xx.x",
median = format_sigfig(3),
range = fmt_sigfig_range(3)
range = format_sigfig(3, "range")
)
)
```
Expand Down

0 comments on commit bc5ee98

Please sign in to comment.