Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions R/data.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
#' Data frame imported from the [CDISC SDTM/ADaM Pilot Project](https://github.com/cdisc-org/sdtm-adam-pilot-project)
#' @name adam
#' @keywords datasets
#' @returns Datasets in tibble format.
#' @examples
#' head(ADSL)
#' head(ADAE)
#' head(ADTTE)
#' head(ADLB)
"ADSL"

#' @rdname adam
Expand Down
5 changes: 2 additions & 3 deletions R/shuffle_ard.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
#' logical representing whether or not to trim away statistic-level metadata and filter
#' only on numeric statistic values.
#'
#' @return a tibble
#' @returns A tibble.
#' @rdname deprecated
#' @export
#'
#' @examples
#' bind_ard(
#' ard_tabulate(ADSL, by = "ARM", variables = "AGEGR1"),
Expand Down Expand Up @@ -145,7 +144,7 @@ shuffle_ard <- function(x, trim = TRUE) {
#' @param ... ([`dynamic-dots`][rlang::dyn-dots])\cr
#' columns to search within
#' @keywords internal
#'
#' @returns A list with the warnings and errors.
#' @examples
#' ard <- ard_summary(
#' ADSL,
Expand Down
9 changes: 9 additions & 0 deletions man/adam.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/deprecated.Rd

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

3 changes: 3 additions & 0 deletions man/dot-detect_msgs.Rd

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

63 changes: 29 additions & 34 deletions tests/testthat/_snaps/add_calculated_row.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,47 @@
# add_calculated_row(x)

Code
apply_fmt_fun(add_calculated_row(ard_summary(mtcars, variables = mpg), expr = max -
min, stat_name = "range"))
out
Message
{cards} data frame: 9 x 9
{cards} data frame: 9 x 8
Output
variable context stat_name stat_label stat stat_fmt
1 mpg summary N N 32 32
2 mpg summary mean Mean 20.091 20.1
3 mpg summary sd SD 6.027 6.0
4 mpg summary median Median 19.2 19.2
5 mpg summary p25 Q1 15.35 15.4
6 mpg summary p75 Q3 22.8 22.8
7 mpg summary min Min 10.4 10.4
8 mpg summary max Max 33.9 33.9
9 mpg summary range range 23.5 23.5
variable context stat_name stat_label stat fmt_fun
1 mpg summary N N 32 0
2 mpg summary mean Mean 20.091 1
3 mpg summary sd SD 6.027 1
4 mpg summary median Median 19.2 1
5 mpg summary p25 Q1 15.35 1
6 mpg summary p75 Q3 22.8 1
7 mpg summary min Min 10.4 1
8 mpg summary max Max 33.9 1
9 mpg summary range range 23.5 1
Message
i 3 more variables: fmt_fun, warning, error
i 2 more variables: warning, error

---

Code
apply_fmt_fun(add_calculated_row(ard_summary(mtcars, variables = mpg), expr = dplyr::case_when(
mean > median ~ "Right Skew", mean < median ~ "Left Skew", .default = "Symmetric"),
stat_name = "skew"))
out2
Message
{cards} data frame: 9 x 9
{cards} data frame: 9 x 8
Output
variable context stat_name stat_label stat stat_fmt
1 mpg summary N N 32 32
2 mpg summary mean Mean 20.091 20.1
3 mpg summary sd SD 6.027 6.0
4 mpg summary median Median 19.2 19.2
5 mpg summary p25 Q1 15.35 15.4
6 mpg summary p75 Q3 22.8 22.8
7 mpg summary min Min 10.4 10.4
8 mpg summary max Max 33.9 33.9
9 mpg summary skew skew Right Sk… Right Skew
variable context stat_name stat_label stat fmt_fun
1 mpg summary N N 32 0
2 mpg summary mean Mean 20.091 1
3 mpg summary sd SD 6.027 1
4 mpg summary median Median 19.2 1
5 mpg summary p25 Q1 15.35 1
6 mpg summary p75 Q3 22.8 1
7 mpg summary min Min 10.4 1
8 mpg summary max Max 33.9 1
9 mpg summary skew skew Right Sk… <fn>
Message
i 3 more variables: fmt_fun, warning, error
i 2 more variables: warning, error

# add_calculated_row(expr) messaging
# add_calculated_row(expr) errors when a variable is not present

Code
add_calculated_row(ard_summary(mtcars, variables = mpg), expr = not_a_stat * 2,
stat_name = "this_doesnt_work")
add_calculated_row(tbl, expr = not_a_stat * 2, stat_name = "this_doesnt_work")
Condition
Error in `add_calculated_row()`:
! There was an error calculating the new statistic. See below:
Expand All @@ -54,8 +50,7 @@
# add_calculated_row(by) messaging

Code
add_calculated_row(ard_summary(mtcars, variables = mpg, by = cyl), expr = max -
min, stat_name = "range", by = "context")
add_calculated_row(tbl, expr = max - min, stat_name = "range", by = "context")
Condition
Error in `add_calculated_row()`:
! Duplicate statistics present within `by` groups: "N", "mean", "sd", "median", "p25", "p75", "min", "max", "N", "mean", "sd", "median", "p25", "p75", "min", and "max"
Expand Down
5 changes: 2 additions & 3 deletions tests/testthat/_snaps/ard_formals.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# ard_formals() works

Code
ard_formals(fun = mcnemar.test, arg_names = "correct")
out
Message
{cards} data frame: 1 x 3
Output
Expand All @@ -11,8 +11,7 @@
---

Code
ard_formals(fun = asNamespace("stats")[["t.test.default"]], arg_names = c("mu",
"paired", "var.equal", "conf.level"), passed_args = list(conf.level = 0.9))
out
Message
{cards} data frame: 4 x 3
Output
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/_snaps/as_nested_list.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# as_nested_list() works

Code
as_nested_list(ard_summary(mtcars, by = "cyl", variables = "hp"))
as_nested_list(tbl)
Output
$variable
$variable$hp
Expand Down
132 changes: 65 additions & 67 deletions tests/testthat/_snaps/mock.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
# mock_categorical()

Code
apply_fmt_fun(mock_categorical(variables = list(AGEGR1 = factor(c("<65", "65-80", ">80"), levels = c("<65", "65-80", ">80"))),
by = list(TRTA = c("Placebo", "Xanomeline High Dose", "Xanomeline Low Dose"))))
out
Message
{cards} data frame: 27 x 12
{cards} data frame: 27 x 11
Output
group1 group1_level variable variable_level stat_name stat_label stat stat_fmt
1 TRTA Placebo AGEGR1 <65 n n xx
2 TRTA Placebo AGEGR1 <65 p % xx.x
3 TRTA Placebo AGEGR1 <65 N N xx
4 TRTA Placebo AGEGR1 65-80 n n xx
5 TRTA Placebo AGEGR1 65-80 p % xx.x
6 TRTA Placebo AGEGR1 65-80 N N xx
7 TRTA Placebo AGEGR1 >80 n n xx
8 TRTA Placebo AGEGR1 >80 p % xx.x
9 TRTA Placebo AGEGR1 >80 N N xx
10 TRTA Xanomeli… AGEGR1 <65 n n xx
group1 group1_level variable variable_level stat_name stat_label stat
1 TRTA Placebo AGEGR1 <65 n n
2 TRTA Placebo AGEGR1 <65 p %
3 TRTA Placebo AGEGR1 <65 N N
4 TRTA Placebo AGEGR1 65-80 n n
5 TRTA Placebo AGEGR1 65-80 p %
6 TRTA Placebo AGEGR1 65-80 N N
7 TRTA Placebo AGEGR1 >80 n n
8 TRTA Placebo AGEGR1 >80 p %
9 TRTA Placebo AGEGR1 >80 N N
10 TRTA Xanomeli… AGEGR1 <65 n n
Message
i 17 more rows
i Use `print(n = ...)` to see more rows
Expand All @@ -34,29 +33,29 @@
# mock_continuous()

Code
apply_fmt_fun(mock_continuous(variables = c("AGE", "BMIBL")))
out
Message
{cards} data frame: 16 x 9
{cards} data frame: 16 x 8
Output
variable context stat_name stat_label stat stat_fmt
1 AGE continuo… N N xx
2 AGE continuo… mean Mean xx.x
3 AGE continuo… sd SD xx.x
4 AGE continuo… median Median xx.x
5 AGE continuo… p25 Q1 xx.x
6 AGE continuo… p75 Q3 xx.x
7 AGE continuo… min Min xx.x
8 AGE continuo… max Max xx.x
9 BMIBL continuo… N N xx
10 BMIBL continuo… mean Mean xx.x
11 BMIBL continuo… sd SD xx.x
12 BMIBL continuo… median Median xx.x
13 BMIBL continuo… p25 Q1 xx.x
14 BMIBL continuo… p75 Q3 xx.x
15 BMIBL continuo… min Min xx.x
16 BMIBL continuo… max Max xx.x
variable context stat_name stat_label stat fmt_fun
1 AGE continuo… N N <fn>
2 AGE continuo… mean Mean <fn>
3 AGE continuo… sd SD <fn>
4 AGE continuo… median Median <fn>
5 AGE continuo… p25 Q1 <fn>
6 AGE continuo… p75 Q3 <fn>
7 AGE continuo… min Min <fn>
8 AGE continuo… max Max <fn>
9 BMIBL continuo… N N <fn>
10 BMIBL continuo… mean Mean <fn>
11 BMIBL continuo… sd SD <fn>
12 BMIBL continuo… median Median <fn>
13 BMIBL continuo… p25 Q1 <fn>
14 BMIBL continuo… p75 Q3 <fn>
15 BMIBL continuo… min Min <fn>
16 BMIBL continuo… max Max <fn>
Message
i 3 more variables: fmt_fun, warning, error
i 2 more variables: warning, error

# mock_continuous() messaging

Expand All @@ -69,21 +68,20 @@
# mock_dichotomous()

Code
apply_fmt_fun(mock_dichotomous(variables = list(AGEGR1 = factor("65-80", levels = c("<65", "65-80", ">80"))), by = list(TRTA = c(
"Placebo", "Xanomeline High Dose", "Xanomeline Low Dose"))))
out
Message
{cards} data frame: 9 x 12
{cards} data frame: 9 x 11
Output
group1 group1_level variable variable_level stat_name stat_label stat stat_fmt
1 TRTA Placebo AGEGR1 65-80 n n xx
2 TRTA Placebo AGEGR1 65-80 p % xx.x
3 TRTA Placebo AGEGR1 65-80 N N xx
4 TRTA Xanomeli… AGEGR1 65-80 n n xx
5 TRTA Xanomeli… AGEGR1 65-80 p % xx.x
6 TRTA Xanomeli… AGEGR1 65-80 N N xx
7 TRTA Xanomeli… AGEGR1 65-80 n n xx
8 TRTA Xanomeli… AGEGR1 65-80 p % xx.x
9 TRTA Xanomeli… AGEGR1 65-80 N N xx
group1 group1_level variable variable_level stat_name stat_label stat
1 TRTA Placebo AGEGR1 65-80 n n
2 TRTA Placebo AGEGR1 65-80 p %
3 TRTA Placebo AGEGR1 65-80 N N
4 TRTA Xanomeli… AGEGR1 65-80 n n
5 TRTA Xanomeli… AGEGR1 65-80 p %
6 TRTA Xanomeli… AGEGR1 65-80 N N
7 TRTA Xanomeli… AGEGR1 65-80 n n
8 TRTA Xanomeli… AGEGR1 65-80 p %
9 TRTA Xanomeli… AGEGR1 65-80 N N
Message
i 4 more variables: context, fmt_fun, warning, error

Expand All @@ -100,23 +98,23 @@
# mock_missing()

Code
apply_fmt_fun(mock_missing(variables = c("AGE", "BMIBL")))
out
Message
{cards} data frame: 10 x 9
{cards} data frame: 10 x 8
Output
variable context stat_name stat_label stat stat_fmt
1 AGE missing N_obs Vector L… xx
2 AGE missing N_miss N Missing xx
3 AGE missing N_nonmiss N Non-mi… xx
4 AGE missing p_miss % Missing xx.x
5 AGE missing p_nonmiss % Non-mi… xx.x
6 BMIBL missing N_obs Vector L… xx
7 BMIBL missing N_miss N Missing xx
8 BMIBL missing N_nonmiss N Non-mi… xx
9 BMIBL missing p_miss % Missing xx.x
10 BMIBL missing p_nonmiss % Non-mi… xx.x
variable context stat_name stat_label stat fmt_fun
1 AGE missing N_obs Vector L… <fn>
2 AGE missing N_miss N Missing <fn>
3 AGE missing N_nonmiss N Non-mi… <fn>
4 AGE missing p_miss % Missing <fn>
5 AGE missing p_nonmiss % Non-mi… <fn>
6 BMIBL missing N_obs Vector L… <fn>
7 BMIBL missing N_miss N Missing <fn>
8 BMIBL missing N_nonmiss N Non-mi… <fn>
9 BMIBL missing p_miss % Missing <fn>
10 BMIBL missing p_nonmiss % Non-mi… <fn>
Message
i 3 more variables: fmt_fun, warning, error
i 2 more variables: warning, error

# mock_missing() messaging

Expand All @@ -129,7 +127,7 @@
# mock_attributes()

Code
mock_attributes(label = list(AGE = "Age", BMIBL = "Baseline BMI"))
out
Message
{cards} data frame: 4 x 8
Output
Expand All @@ -152,12 +150,12 @@
# mock_total_n()

Code
apply_fmt_fun(mock_total_n())
out
Message
{cards} data frame: 1 x 9
{cards} data frame: 1 x 8
Output
variable context stat_name stat_label stat stat_fmt
1 ..ard_total_n.. total_n N N xx
variable context stat_name stat_label stat fmt_fun
1 ..ard_total_n.. total_n N N <fn>
Message
i 3 more variables: fmt_fun, warning, error
i 2 more variables: warning, error

Loading
Loading