Skip to content

Commit

Permalink
update to 0.2.0 [skip vbump] (#22)
Browse files Browse the repository at this point in the history
- [x] - requirement #0.15 'Format of xx.xx (xx.xx, xx.xx)' is not
covered by any test
- [x] - requirement #0.27 'Refactor active arm' is not covered by any
test
- [x] - requirement #0.31 'Format of (xx%, xx%)' is not covered by any
test
- [x] - requirement #0.36 'survival proportion afun' is not covered by
any test
- [x] - requirement #0.40 'Generate flextable for preview first page' is
not covered by any test
- [x] - requirement #0.53 'Format of xx.xx (xx.x)' is not covered by any
test

---------

Signed-off-by: Joe Zhu <[email protected]>
  • Loading branch information
shajoezhu authored Dec 9, 2024
1 parent 7b697e1 commit 9af3941
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 8 deletions.
5 changes: 3 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
Type: Package
Package: autoslider.core
Title: Slide Automation for Tables, Listings and Figures
Version: 0.1.0.9004
Version: 0.2.0
Authors@R: c(
person("Joe", "Zhu", , "[email protected]", role = c("cre", "aut")),
person("Joe", "Zhu", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0001-7566-2787")),
person("Heng", "Wang", role = "aut"),
person("Yinqi", "Zhao", role = "aut"),
person("Bo", "Ci", role = "aut"),
Expand Down
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ export(preprocess_t_ds)
export(purple_format)
export(read_spec)
export(red_format)
export(s_proportion_1)
export(s_surv_time_1)
export(save_output)
export(save_output.autoslider_error)
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# autoslider.core 0.1.0.9004
# autoslider.core 0.2.0

### New features

Expand Down
5 changes: 2 additions & 3 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ trim_perc <- function(x, output) {
#' @return formatted values
#' @export
perc_perc <- function(x, output) {
paste0(round(x[1] * 100, 1), "% (", round(x[2] * 100, 1), "%)")
paste0(new_round(x[1] * 100, 0), "% (", new_round(x[2] * 100, 0), "%)")
}

#' Format of xx.xx (xx.xx, xx.xx)
Expand All @@ -123,7 +123,7 @@ perc_perc <- function(x, output) {
#' @return formatted values
#' @export
format_3d <- function(x, output) {
paste0(round(x[1], 2), " (", round(x[2], 2), ", ", round(x[3], 2), ")")
paste0(new_round(x[1], 2), " (", new_round(x[2], 2), ", ", new_round(x[3], 2), ")")
}


Expand Down Expand Up @@ -175,7 +175,6 @@ s_surv_time_1 <- function(df, .var, is_event, control = control_surv_time()) {
#' @param long flag
#' @return A function suitable for use in rtables::analyze() with element selection,
#' reformatting, and relabeling performed automatically.
#' @export
s_proportion_1 <- function(x, conf_level = 0.95,
method = c(
"waldcc", "wald", "clopper-pearson",
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,4 @@ tlg
yaml
yml
yyyy
ORCID
2 changes: 1 addition & 1 deletion man/autoslider.core-package.Rd

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

26 changes: 26 additions & 0 deletions tests/testthat/_snaps/helper_functions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Test some functions in helper_functions.R

Code
mutate_actarm(adsl)
Output
# A tibble: 400 x 63
STUDYID USUBJID SUBJID SITEID AGE AGEU SEX RACE ETHNIC COUNTRY DTHFL
<chr> <chr> <chr> <chr> <int> <fct> <fct> <fct> <fct> <fct> <fct>
1 AB12345-1 AB12345~ id-128 CHN-3 32 YEARS M ASIAN HISPA~ CHN Y
2 AB12345-2 AB12345~ id-262 CHN-15 35 YEARS M BLAC~ NOT H~ CHN N
3 AB12345-1 AB12345~ id-378 RUS-3 30 YEARS F ASIAN NOT H~ RUS N
4 AB12345-2 AB12345~ id-220 CHN-11 26 YEARS F ASIAN NOT H~ CHN N
5 AB12345-1 AB12345~ id-267 CHN-7 40 YEARS M ASIAN NOT H~ CHN N
6 AB12345-2 AB12345~ id-201 CHN-15 49 YEARS M ASIAN NOT H~ CHN Y
7 AB12345-1 AB12345~ id-45 USA-1 34 YEARS F ASIAN NOT H~ USA N
8 AB12345-2 AB12345~ id-261 USA-1 32 YEARS F ASIAN NOT H~ USA N
9 AB12345-1 AB12345~ id-173 NGA-11 24 YEARS F BLAC~ NOT H~ NGA N
10 AB12345-2 AB12345~ id-307 CHN-1 24 YEARS M ASIAN NOT H~ CHN Y
# i 390 more rows
# i 52 more variables: INVID <chr>, INVNAM <chr>, ARM <fct>, ARMCD <fct>,
# ACTARM <fct>, ACTARMCD <fct>, TRT01P <fct>, TRT01A <fct>, TRT02P <fct>,
# TRT02A <fct>, REGION1 <fct>, STRATA1 <fct>, STRATA2 <fct>, BMRKR1 <dbl>,
# BMRKR2 <fct>, ITTFL <fct>, SAFFL <fct>, BMEASIFL <fct>, BEP01FL <fct>,
# AEWITHFL <fct>, RANDDT <date>, TRTSDTM <dttm>, TRTEDTM <dttm>,
# TRT01SDTM <dttm>, TRT01EDTM <dttm>, TRT02SDTM <dttm>, TRT02EDTM <dttm>, ...

46 changes: 46 additions & 0 deletions tests/testthat/_snaps/slides_preview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Test slides preview

Code
ret$header$dataset
Output
V1 V2 V3 V4 V5
1 A: Drug X B: Placebo C: Combination All Patients

---

Code
ret$body$dataset
Output
V1 V2 V3
1 Sex
2 F 79 (59%) 82 (61.2%)
3 M 55 (41%) 52 (38.8%)
4 Age
5 Median 33.00 35.00
6 Min - Max 21.0 - 50.0 21.0 - 62.0
7 Race
8 ASIAN 68 (50.7%) 67 (50%)
9 BLACK OR AFRICAN AMERICAN 31 (23.1%) 28 (20.9%)
10 WHITE 27 (20.1%) 26 (19.4%)
11 AMERICAN INDIAN OR ALASKA NATIVE 8 (6%) 11 (8.2%)
12 MULTIPLE 0 1 (0.7%)
13 NATIVE HAWAIIAN OR OTHER PACIFIC ISLANDER 0 1 (0.7%)
14 OTHER 0 0
15 UNKNOWN 0 0
V4 V5
1
2 70 (53%) 231 (57.8%)
3 62 (47%) 169 (42.2%)
4
5 35.00 34.00
6 20.0 - 69.0 20.0 - 69.0
7
8 73 (55.3%) 208 (52%)
9 32 (24.2%) 91 (22.8%)
10 21 (15.9%) 74 (18.5%)
11 6 (4.5%) 25 (6.2%)
12 0 1 (0.2%)
13 0 1 (0.2%)
14 0 0
15 0 0

30 changes: 30 additions & 0 deletions tests/testthat/test-formats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
testthat::test_that("new_round function", {
da1 <- data.frame(
raw = seq(0, 1, 0.0005),
r = unlist(lapply(seq(0, 1, 0.0005) * 100, new_round, digits = 1))
)
expect_true(all(table(da1$r[2:2001]) == 2))

da2 <- data.frame(
raw = seq(0, 1, 0.00005),
r = unlist(lapply(seq(0, 1, 0.00005) * 100, new_round, digits = 2))
)
expect_true(all(table(da2$r[2:20001]) == 2))
})


testthat::test_that("xx.xx (xx.xx)", {
expect_identical(trim_perc(c(10, 0.6375)), "10 (63.75)")
})

testthat::test_that("xx.xx (xx.x)", {
expect_identical(trim_perc1(c(10, 0.6375)), "10 (63.8)")
})

testthat::test_that("(xx\\%, xx\\%)", {
expect_identical(perc_perc(c(0.2, 0.6375)), "20% (64%)")
})

testthat::test_that("xx.xx (xx.xx, xx.xx)", {
expect_identical(format_3d(c(10, 0.6375, 0.2413)), "10 (0.64, 0.24)")
})
4 changes: 4 additions & 0 deletions tests/testthat/test-helper_functions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("Test some functions in helper_functions.R", {
testthat::expect_no_error(mutate_actarm(adsl))
testthat::expect_snapshot(mutate_actarm(adsl))
})
7 changes: 7 additions & 0 deletions tests/testthat/test-slides_preview.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
test_that("Test slides preview", {
adsl <- eg_adsl
out <- t_dm_slide(adsl, "TRT01P", c("SEX", "AGE", "RACE"))
expect_no_error(ret <- out %>% slides_preview())
expect_snapshot(ret$header$dataset)
expect_snapshot(ret$body$dataset)
})

0 comments on commit 9af3941

Please sign in to comment.