Skip to content

Commit

Permalink
adding tests (#8)
Browse files Browse the repository at this point in the history
close #4

---------

Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
  • Loading branch information
shajoezhu and github-actions[bot] authored Nov 13, 2024
1 parent 98f1764 commit 0166b3f
Show file tree
Hide file tree
Showing 25 changed files with 1,038 additions and 47 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export(lyt_to_side_by_side)
export(lyt_to_side_by_side_two_data)
export(mutate_actarm)
export(na_replace)
export(null_report)
export(orange_format)
export(perc_perc)
export(ph_with_img)
Expand Down
41 changes: 41 additions & 0 deletions R/null_report.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#' Null report
#'
#' @author Thomas Neitmann (`neitmant`)
#' @export
#'
#' @details
#' This will create a null report similar as STREAM does. You can use
#' it inside output functions as shown in the example below.
#'
#' @examples
#' library(dplyr)
#' library(filters)
#' data <- list(
#' adsl = eg_adsl,
#' adae = eg_adae %>% mutate(AREL = "")
#' )
#'
#' null_report()
#'
#' ## An example how to use the `null_report()` inside an output function
#' t_ae <- function(datasets) {
#' trt <- "ACTARM"
#' anl <- semi_join(
#' datasets$adae,
#' datasets$adsl,
#' by = c("STUDYID", "USUBJID")
#' )
#'
#' return(null_report())
#' }
#'
#' data %>%
#' apply_filter("SER_SE") %>%
#' t_ae()
#'
null_report <- function() {
rtable(
header = " ",
rrow("", "Null Report: No observations met the reporting criteria for inclusion in this output.")
)
}
3 changes: 2 additions & 1 deletion R/save_output.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
#'
#' @examples
#' library(dplyr)
#' adsl <- eg_adsl %>% filter(SAFFL == "Y") %>%
#' adsl <- eg_adsl %>%
#' filter(SAFFL == "Y") %>%
#' mutate(TRT01P = factor(TRT01P, levels = c("A: Drug X", "B: Placebo")))
#' output_dir <- tempdir()
#' t_dm_slide(adsl, "TRT01P", c("SEX", "AGE", "RACE", "ETHNIC", "COUNTRY")) %>%
Expand Down
5 changes: 3 additions & 2 deletions R/t_ae_slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ t_ae_slide <- function(adsl, adae, arm = "TRT01A",
return(null_report())
} else {
lyt <- build_table_header(adsl, arm,
split_by_study = split_by_study,
side_by_side = side_by_side)
split_by_study = split_by_study,
side_by_side = side_by_side
)

lyt <- lyt %>%
split_rows_by(
Expand Down
12 changes: 7 additions & 5 deletions R/t_dm_slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@
#' generate_slides(out1, "dm.pptx")
#'
#' out2 <- t_dm_slide(adsl, "TRT01P", c("SEX", "AGE", "RACE", "ETHNIC", "COUNTRY"),
#' split_by_study = TRUE)
#' split_by_study = TRUE
#' )
#' print(out2)
#'
t_dm_slide <- function(adsl,
arm = "TRT01P",
vars = c("AGEGR1", "SEX", "RACE", "BECOG", "BBMI"),
vars = c("AGE", "SEX", "RACE"),
stats = c("median", "range", "count_fraction"),
split_by_study = FALSE,
side_by_side = NULL) {
Expand All @@ -39,8 +40,10 @@ t_dm_slide <- function(adsl,
adsl1 <- adsl %>%
select(all_of(c("STUDYID", "USUBJID", arm, vars, extra)))

lyt <- build_table_header(adsl1, arm, split_by_study = split_by_study,
side_by_side = side_by_side)
lyt <- build_table_header(adsl1, arm,
split_by_study = split_by_study,
side_by_side = side_by_side
)

lyt <- lyt %>%
analyze_vars(
Expand All @@ -55,7 +58,6 @@ t_dm_slide <- function(adsl,
result <- lyt_to_side_by_side(lyt, adsl1, side_by_side)

if (is.null(side_by_side)) {

# adding "N" attribute
arm <- col_paths(result)[[1]][1]

Expand Down
21 changes: 1 addition & 20 deletions R/util.R
Original file line number Diff line number Diff line change
Expand Up @@ -669,29 +669,12 @@ lyt_to_side_by_side_two_data <- function(lyt, anl, alt_counts_df, side_by_side =
return(result)
}

#' Checker of data frame display per patient (or not)
#'
#' @param pp per patient
#' @param colname name of column
if_display_pp <- function(pp, colname = FALSE) {
if (!pp) {
if (!colname) {
return("USUBJID")
}
return("Patient ID")
}
return(NULL)
}

do_call <- function(fun, ...) {
args <- list(...)
do.call(fun, args[intersect(names(args), formalArgs(fun))])
}

strip_NA <- function(input) {
return(input[which(input != "NA")])
}


build_table_header <- function(anl,
arm,
Expand Down Expand Up @@ -722,7 +705,5 @@ build_table_header <- function(anl,


get_version_label_output <- function() {
NULL
NULL
}


Empty file modified inst/WORDLIST
100644 → 100755
Empty file.
16 changes: 0 additions & 16 deletions man/if_display_pp.Rd

This file was deleted.

45 changes: 45 additions & 0 deletions man/null_report.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/save_output.Rd

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

5 changes: 3 additions & 2 deletions man/t_dm_slide.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pkg_name <- "autoslider.core"
library(testthat)
test_check(pkg_name, reporter = ParallelProgressReporter$new())
Loading

0 comments on commit 0166b3f

Please sign in to comment.