Package 'autoslider.core'

Title: Slides automation with R
Description: Slides automation with R.
Authors: Joe Zhu [cre, aut], Heng Wang [aut], Yinqi Zhao [aut], Bo Ci [aut], Liming Li [aut], Laura Wang [ctb], Xiaoli Duan [aut], Stefan Pascal Thoma [aut], Thomas Neitmann [ctb], Miles Almond [aut], Mahdi About [ctb], Kai Lim [ctb], Nolan Steed [ctb], Daoling Pang [ctb], Elisabeth Deutschmann [ctb], Chenkai Lv [aut]
Maintainer: Joe Zhu <[email protected]>
License: file LICENSE
Version: 0.0.1.9033
Built: 2024-11-18 07:23:38 UTC
Source: https://github.com/insightsengineering/autoslider.core

Help Index


autoslider.core Package

Description

Slides automation with R.

Author(s)

Maintainer: Joe Zhu [email protected]

Authors:

  • Heng Wang

  • Yinqi Zhao

  • Bo Ci

  • Liming Li

  • Xiaoli Duan

  • Stefan Pascal Thoma

  • Miles Almond

  • Chenkai Lv

Other contributors:

  • Laura Wang [contributor]

  • Thomas Neitmann [contributor]

  • Mahdi About [contributor]

  • Kai Lim [contributor]

  • Nolan Steed [contributor]

  • Daoling Pang [contributor]

  • Elisabeth Deutschmann [contributor]

See Also

Useful links:


autoslider_error class

Description

autoslider_error class

Usage

autoslider_error(x, spec, step)

Arguments

x

character scaler

spec

spec should be a list containing "program" and "suffix"

step

step is a character indicating in which step the pipeline encounter error

Details

this function is used to create autoslider_error object. this function is for internal use only to create the autoslider_error object. It enable us for further functionalities, like providing help on easy debugging, e.g. if the error is inside the user function, provide the call and let the user run the code outside the pipeline.


Table color and font

Description

Zebra themed color

Usage

autoslider_format(
  ft,
  odd_header = "#0EAED5",
  odd_body = "#EBF5FA",
  even_header = "#0EAED5",
  even_body = "#D0E4F2",
  font_name = "arial",
  body_font_size = 12,
  header_font_size = 14
)

blue_format(ft, ...)

orange_format(ft, ...)

red_format(ft, ...)

purple_format(ft, ...)

autoslider_dose_format(ft, header_vals = names(ft))

white_format(ft, ...)

black_format(ft, ...)

Arguments

ft

flextable object

odd_header

Hex color code, default to deep sky blue

odd_body

Hex color code, default to alice blue

even_header

Hex color code, default to slate gray

even_body

Hex color code, default to slate gray

font_name

Font name, default to arial

body_font_size

Font size of the table content, default to 12

header_font_size

Font size of the table header, default to 14

...

arguments passed to program

header_vals

Header

Functions

  • autoslider_format(): User defined color code and font size

  • blue_format(): Blue color theme

  • orange_format(): Orange color theme

  • red_format(): Red color theme

  • purple_format(): Purple color theme

  • autoslider_dose_format(): 'AutoslideR' dose formats

  • white_format(): White color theme

  • black_format(): Black color theme


Build table header, a utility function to help with construct structured header for table layout

Description

Build table header, a utility function to help with construct structured header for table layout

Usage

build_table_header(anl, arm, split_by_study, side_by_side)

Arguments

anl

analysis data object

arm

Arm variable for column split

split_by_study

if true, construct structured header with the study ID

side_by_side

A logical value indicating whether to display the data side by side.


Create location container to center the figure, based on ppt size and user specified figure size

Description

Create location container to center the figure, based on ppt size and user specified figure size

Usage

center_figure_loc(fig_width, fig_height, ppt_width, ppt_height)

Arguments

fig_width

Figure width

fig_height

Figure height

ppt_width

Slide width

ppt_height

Slide height

Value

Location for a placeholder from scratch


create location container to center the table

Description

create location container to center the table

Usage

center_table_loc(ft, ppt_width, ppt_height)

Arguments

ft

Flextable object

ppt_width

Powerpoint width

ppt_height

Powerpoint height

Value

Location for a placeholder


Assert function to check the cutoff

Description

Assert function to check the cutoff

Usage

check_and_set_cutoff(data, cutoff)

Arguments

data

dataframe

cutoff

cutoff threshold


Concatenate arguments into a string

Description

Concatenate arguments into a string

Usage

dec_paste(...)

Arguments

...

arguments passed to program


generic function decorate

Description

generic function decorate

s3 method for decorate

Usage

decorate(x, ...)

decorate(x, ...)

Arguments

x

object to decorate

...

additional arguments passed to methods


Decorate outputs

Description

Decorate outputs with titles and footnotes

Usage

decorate_outputs(
  outputs,
  generic_title = NULL,
  generic_footnote = "Confidential and for internal use only",
  version_label = get_version_label_output(),
  for_test = FALSE
)

Arguments

outputs

'list' of output objects as created by 'generate_outputs'

generic_title

'character' vector of titles

generic_footnote

'character' vector of footnotes

version_label

'character'. A version label to be added to the title.

for_test

'logic' CICD parameter

Details

'generic_title' and 'generic_footnote' will be added to *all* outputs. The use case is to add information such as protocol number and snapshot date defined in a central place (e.g. metadata.yml) to *every* output.

'version_label' must be either '"DRAFT"', '"APPROVED"' or 'NULL'. By default, when outputs are created on the master branch it is set to 'NULL', i.e. no version label will be displayed. Otherwise '"DRAFT"' will be added. To add '"APPROVED"' to the title you will need to explicitly set 'version_label = "APPROVED"'.


decorate listing

Description

decorate listing

Usage

## S4 method for signature 'listing_df'
decorate(x, titles = "", footnotes = "", paper = "P8", for_test = FALSE, ...)

Arguments

x

A listing_df object representing the data to be decorated.

titles

Title to be added to the table.

footnotes

Footnote to be added to the table

paper

Orientation and font size as string, e.g. "P8"; "L11"

for_test

'logic' CICD parameter

...

Additional arguments. not used.


Decorate TableTree

Description

Decorate TableTree

Usage

## S4 method for signature 'VTableTree'
decorate(x, titles = "", footnotes = "", paper = "P8", for_test = FALSE, ...)

Arguments

x

A VTableTree object representing the data to be decorated.

titles

Title to be added to the table.

footnotes

Footnote to be added to the table

paper

Orientation and font size as string, e.g. "P8"; "L11"

for_test

'logic' CICD parameter

...

Additional arguments passed to the decoration function.


decorate method for autoslider_error class

Description

decorate method for autoslider_error class

Usage

decorate.autoslider_error(x, ...)

Arguments

x

object to decorate

...

additional arguments. not used.


default method to decorate

Description

default method to decorate

Usage

decorate.default(x, ...)

Arguments

x

object to decorate

...

additional arguments. not used.


Decorate ggplot object

Description

Decorate ggplot object

Usage

decorate.ggplot(
  x,
  titles = "",
  footnotes = "",
  paper = "L11",
  for_test = FALSE,
  ...
)

Arguments

x

An object to decorate

titles

Plot titles

footnotes

Plot footnotes

paper

Paper size, by default "L11"

for_test

'logic' CICD parameter

...

additional arguments. not used.

Details

The paper default paper size, 'L11', indicate that the fontsize is 11. The fontsize of the footnotes, is the fontsize of the titles minus 2.


decorate grob

Description

decorate grob

Usage

decorate.grob(x, titles, footnotes, paper = "L11", for_test = FALSE, ...)

Arguments

x

object to decorate

titles

graph titles

footnotes

graph footnotes

paper

paper size. default is "L8".

for_test

'logic' CICD parameter

...

Additional arguments. not used.

Details

The paper default paper size, 'L11', indicate that the fontsize is 11. The fontsize of the footnotes, is the fontsize of the titles minus 2.


decorate list of grobs

Description

decorate list of grobs

Usage

decorate.list(x, titles, footnotes, paper = "L11", for_test = FALSE, ...)

Arguments

x

object to decorate

titles

graph titles

footnotes

graph footnotes

paper

paper size. default is "L11".

for_test

'logic' CICD parameter

...

additional arguments. not used

Details

The paper default paper size, 'L11', indicate that the fontsize is 11. The fontsize of the footnotes, is the fontsize of the titles minus 2.


Cached ADAE

Description

Cached ADAE data

Usage

data(eg_adae)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 1934 rows and 93 columns.


Cached ADEG

Description

Cached ADEG data

Usage

data(eg_adeg)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 13600 rows and 88 columns.


Cached ADEX

Description

Cached ADEX data

Usage

data(eg_adex)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 6400 rows and 79 columns.


Cached ADLB

Description

Cached ADLB data

Usage

data(eg_adlb)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 8400 rows and 102 columns.


Cached ADRS

Description

Cached ADRS data

Usage

data(eg_adrs)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 3200 rows and 65 columns.


Cached ADSL

Description

Cached ADSL data

Usage

data(eg_adsl)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 400 rows and 55 columns.


Cached ADTR

Description

Cached ADTR data

Usage

data(eg_adtr)

Format

An object of class data.frame with 2800 rows and 76 columns.


Cached ADTTE

Description

Cached ADTTE data

Usage

data(eg_adtte)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 2000 rows and 67 columns.


Cached ADVS

Description

Cached ADVS data

Usage

data(eg_advs)

Format

An object of class tbl_df (inherits from tbl, data.frame) with 16800 rows and 87 columns.


Does do.call quicker, and avoids issues with debug mode within do.call

Description

copied from ms showcase app

Usage

fastDoCall(what, args, quote = FALSE, envir = parent.frame())

Arguments

what

either a function or a non-empty character string naming the function to be called.

args

a list of arguments to the function call. The names attribute of args gives the argument names.

quote

a logical value indicating whether to quote the arguments.

envir

an environment within which to evaluate the call. This will be most useful if what is a character string and the arguments are symbols or quoted expressions.


Add figure to slides

Description

Add figure to slides

Usage

figure_to_slide(
  ppt,
  content,
  decor = TRUE,
  fig_width,
  fig_height,
  figure_loc = ph_location_type("body"),
  ...
)

Arguments

ppt

slide page

content

content to be added

decor

should decoration be added

fig_width

user specified figure width

fig_height

user specified figure height

figure_loc

location of the figure. Defaults to 'ph_location_type("body")'

...

arguments passed to program

Value

slide with the added content


Filter a spec object

Description

Filter a spec object

Usage

filter_spec(spec, filter_expr, verbose = TRUE)

Arguments

spec

A 'spec' object as returned by 'read_spec()'

filter_expr

A 'logical' expression indicating outputs to keep

verbose

Should a message about the number of outputs matching 'filter_spec' be printed? Defaults to 'TRUE'.

Value

A 'spec' object containing only the outputs matching 'filter_expr'

Author(s)

Thomas Neitmann ('neitmant')

Examples

library(dplyr)
spec_file <- system.file("spec.yml", package = "autoslider.core")
spec <- spec_file %>% read_spec()
## Keep only outputs belonging to batch 2
## Not run: 
filter_spec(spec, batch == 2)

## End(Not run)

## Keep only the t_dm_IT output
filter_spec(spec, output == "t_dm_IT")

## Same as above but more verbose
filter_spec(spec, program == "t_dm" && suffix == "IT")

## Keep all t_ae outputs
filter_spec(spec, program == "t_ae")

## Keep all output run on safety population
filter_spec(spec, "SE" %in% suffix)

## Keep t_dm_CHN_IT and t_dm_CHN_SE
filter_spec(spec, program == "t_dm" && suffix %in% c("CHN_IT", "CHN_SE"))

## Keep all tables
filter_spec(spec, grepl("^t_", program))

Format of xx.xx (xx.xx, xx.xx)

Description

Format of xx.xx (xx.xx, xx.xx)

Usage

format_3d(x, output)

Arguments

x

input array

output

output handle


Convert dates from 'yyyy-mm-dd' format into 20APR2019 format 'Datetime' format removes the time and outputs date in the same way Able to handle truncated dates as well (e.g. just the year or year and month)

Description

'dplyr::case_when()' will check all RHS expressions on the input, this means if these expressions return warnings, they will happen even then the input doesn't doesn't satisfy the LHS. For this reason, I had to 'quiet' all 'lubridate' functions. This 'format_date()' function was tested with the inputs in the examples, all gave the expected returned value, so there should be no issues.

Usage

format_date(x)

Arguments

x

vector of dates in character, in 'yyyy-mm-dd' format

Value

A vector.

Examples

# expected to return "2019"
format_date("2019")

# expected to return "20APR2019"
format_date("2019-04-20")

# expected to return ""
format_date("")

# expected to return "18JUN2019"
format_date("2019-06-18T10:32")

# expected to return "APR2019"
format_date("2019-04")

function wrapper to pass filtered data

Description

function wrapper to pass filtered data

Usage

func_wrapper(func, datasets, spec, verbose = TRUE)

Arguments

func

function name

datasets

list of raw datasets

spec

spec

verbose

whether to show verbose information

Value

a wrapped function using filtered adam


General notes

Description

General notes

Usage

gen_notes()

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output


Generate output and apply filters, titles, and footnotes

Description

Generate output and apply filters, titles, and footnotes

Usage

generate_output(program, datasets, spec, verbose_level = 2, ...)

Arguments

program

program name

datasets

list of datasets

spec

spec

verbose_level

Verbose level of messages be displayed. See details for further information.

...

arguments passed to program

Details

'verbose_level' is used to control how many messages are printed out. By default, '2' will show all filter messages and show output generation message. '1' will show output generation message only. '0' will display no message.

Author(s)

Liming Li ('Lil128')

Examples

library(dplyr)
filters::load_filters(
  yaml_file = system.file("filters.yml", package = "autoslider.core"),
  overwrite = TRUE
)

spec_file <- system.file("spec.yml", package = "autoslider.core")
spec <- spec_file %>% read_spec()

data <- list(
  adsl = eg_adsl,
  adae = eg_adae
)
generate_output("t_ae_slide", data, spec$t_ae_slide_SE)

Generate all outputs from a spec

Description

Generate all outputs from a spec

Usage

generate_outputs(spec, datasets, verbose_level = 2)

Arguments

spec

Specification list generated by 'read_spec'

datasets

A 'list' of datasets

verbose_level

Verbose level of messages be displayed. See details for further information.

Details

'verbose_level' is used to control how many messages are printed out. By default, '2' will show all filter messages and show output generation message. '1' will show output generation message only. '0' will display no message.

Author(s)

- Thomas Neitmann ('neitmant') - Liming Li ('Lil128')

Examples

library(dplyr, warn.conflicts = FALSE)
data <- list(
  adsl = eg_adsl,
  adae = eg_adae
)
filters::load_filters(
  yaml_file = system.file("filters.yml", package = "autoslider.core"),
  overwrite = TRUE
)

spec_file <- system.file("spec.yml", package = "autoslider.core")
spec_file %>%
  read_spec() %>%
  filter_spec(output %in% c("t_dm_slide_IT", "t_ae_slide_SE")) %>%
  generate_outputs(datasets = data)

generate slides based on output

Description

generate slides based on output

Usage

generate_slides(
  outputs,
  outfile = "output.pptx",
  template = file.path(system.file(package = "autoslider.core"), "theme/basic.pptx"),
  fig_width = 9,
  fig_height = 6,
  t_lpp = 20,
  t_cpp = 200,
  l_lpp = 20,
  l_cpp = 150,
  ...
)

Arguments

outputs

List of output

outfile

Out file path

template

Template file path

fig_width

figure width in inch

fig_height

figure height in inch

t_lpp

An integer specifying the table lines per page
Specify this optional argument to modify the length of all of the table displays

t_cpp

An integer specifying the table columns per page
Specify this optional argument to modify the width of all of the table displays

l_lpp

An integer specifying the listing lines per page
Specify this optional argument to modify the length of all of the listings display

l_cpp

An integer specifying the listing columns per page
Specify this optional argument to modify the width of all of the listings display

...

arguments passed to program

Examples

# Example 1. When applying to the whole pipeline
library(dplyr)
data <- list(
  adsl = eg_adsl %>% dplyr::mutate(FASFL = SAFFL),
  adae = eg_adae
)


filters::load_filters(
  yaml_file = system.file("filters.yml", package = "autoslider.core"),
  overwrite = TRUE
)


spec_file <- system.file("spec.yml", package = "autoslider.core")
spec_file %>%
  read_spec() %>%
  filter_spec(program %in% c("t_dm_slide")) %>%
  generate_outputs(datasets = data) %>%
  decorate_outputs() %>%
  generate_slides()

# Example 2. When applying to an rtable object or an rlisting object
adsl <- eg_adsl
t_dm_slide(adsl, "TRT01P", c("SEX", "AGE")) %>%
  generate_slides()

Adjust title line break and font size

Description

Adjust title line break and font size

Usage

get_proper_title(title, max_char = 60, title_color = "#1C2B39")

Arguments

title

Character string

max_char

Integer specifying the maximum number of characters in one line

title_color

Title color


Build side by side layout by cbind

Description

Build side by side layout by cbind

Usage

lyt_to_side_by_side(lyt, anl, side_by_side = NULL)

Arguments

lyt

layout object

anl

analysis data object

side_by_side

A logical value indicating whether to display the data side by side.


Build side by side layout by cbind

Description

Build side by side layout by cbind

Usage

lyt_to_side_by_side_two_data(lyt, anl, alt_counts_df, side_by_side = NULL)

Arguments

lyt

layout object

anl

analysis data object

alt_counts_df

alternative data frame for counts

side_by_side

A logical value indicating whether to display the data side by side.


Refactor active arm

Description

Refactor active arm

Usage

mutate_actarm(
  df,
  arm_var = "TRT01A",
  levels = c("PLACEBO + PACLITAXEL + CISPLATIN",
    "ATEZOLIZUMAB + TIRAGOLUMAB + PACLITAXEL + CISPLATIN"),
  labels = c("Pbo+Pbo+PC", "Tira+Atezo+PC")
)

Arguments

df

Input dataframe

arm_var

Arm variable

levels

factor levels

labels

factor labels


Replace NAs to NA

Description

Replace NAs to NA

Usage

na_replace(table_df)

Arguments

table_df

Table dataframe


Founding method

Description

Founding method

Usage

new_round(x, digits = 1)

Arguments

x

number need to be rounded

digits

number of digits


Null report

Description

Null report

Usage

null_report()

Details

This will create a null report similar as STREAM does. You can use it inside output functions as shown in the example below.

Author(s)

Thomas Neitmann ('neitmant')

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()

Format of (xx%, xx%)

Description

Format of (xx%, xx%)

Usage

perc_perc(x, output)

Arguments

x

input array

output

output handle


Placeholder for ph_with_img

Description

Placeholder for ph_with_img

Usage

ph_with_img(ppt, figure, fig_width, fig_height, figure_loc)

Arguments

ppt

power point file

figure

image object

fig_width

width of figure

fig_height

height of figure

figure_loc

location of figure


Preprocess t_dd function

Description

Preprocess t_dd function

Usage

preprocess_t_dd(
  df,
  levels = c("PROGRESSIVE DISEASE", "ADVERSE EVENT", "OTHER", "<Missing>"),
  labels = c("Progressive Disease", "Adverse Events", "Other", "<Missing>")
)

Arguments

df

Input dataframe

levels

factor levels

labels

factor labels


Preprocess t_ds function

Description

Preprocess t_ds function

Usage

preprocess_t_ds(
  df,
  levels = c("Alive: On Treatment", "Alive: In Follow-up", "<Missing>"),
  labels = c("Alive: On Treatment", "Alive: In Follow-up", "<Missing>")
)

Arguments

df

Input dataframe

levels

factor levels

labels

factor labels


Print decorated grob

Description

Print decorated grob

Usage

## S3 method for class 'decoratedGrob'
print(x, ...)

Arguments

x

An object of class 'decoratedGrob'

...

not used.


Print decorated grob set

Description

Print decorated grob set

Usage

## S3 method for class 'decoratedGrobSet'
print(x, ...)

Arguments

x

An object of class 'decoratedGrobSet'

...

not used.


Read yaml spec file

Description

Read yaml spec file and split according to filter lists

Usage

read_spec(spec_file = "spec.yml", metadata = NULL)

Arguments

spec_file

'character'. Path to a yaml spec file

metadata

Metadata of study

Value

An object of class 'spec' which is a 'list' where each element corresponds to one output, e.g. 't_dm_IT'.

Author(s)

- Liming Li ('Lil128') - Thomas Neitmann ('neitmant')

Examples

spec_file <- system.file("spec.yml", package = "autoslider.core")

## Take a look at the 'raw' content of the spec file
cat(readLines(spec_file)[1:24], sep = "\n")

## This is how it looks once read into R
spec <- read_spec(spec_file)
spec[1:3]

survival proportion afun

Description

survival proportion afun

Usage

s_proportion_1(
  x,
  conf_level = 0.95,
  method = c("waldcc", "wald", "clopper-pearson", "wilson", "agresti-coull", "jeffreys"),
  long = FALSE
)

Arguments

x

data vector

conf_level

confidence level

method

type of method for calculation

long

flag


survival time afun

Description

survival time afun

Usage

s_surv_time_1(df, .var, is_event, control = control_surv_time())

Arguments

df

data

.var

variable of interest

is_event

vector indicating event

control

'control_surv_time()' by default


Save an Output

Description

Save an Output

Usage

save_output(output, file_name, save_rds = TRUE)

save_output(output, file_name, save_rds = TRUE)

save_output.autoslider_error(output, file_name, save_rds = TRUE)

## S4 method for signature 'dVTableTree'
save_output(output, file_name, save_rds = TRUE)

save_output.decoratedGrob(output, file_name, save_rds = TRUE)

save_output.decoratedGrobSet(output, file_name, save_rds = TRUE)

save_output.dlisting(output, file_name, save_rds = TRUE)

Arguments

output

Output object, e.g. an 'rtable' or 'grob'

file_name

Full path of the new file *excluding* the extension

save_rds

Saved as an '.rds' files

Details

Tables are saved as RDS file

Value

The input 'object' invisibly

Examples

library(dplyr)
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")) %>%
  decorate(
    title = "Demographic table",
    footnote = ""
  ) %>%
  save_output(
    file_name = file.path(output_dir, "t_dm_SE"),
    save_rds = TRUE
  )

Save a list of outputs

Description

Save a list of outputs

Usage

save_outputs(
  outputs,
  outfolder = file.path("output"),
  generic_suffix = NULL,
  save_rds = TRUE,
  verbose_level = 1
)

Arguments

outputs

'list' of outputs as created by 'generate_outputs'

outfolder

Folder in which to store the 'outputs“

generic_suffix

generic suffix. must be length 1 character or NULL.

save_rds

Should the input 'outputs' be saved as '.rds' files in in addition to '.out' or '.pdf' files? Defaults to 'FALSE'.

verbose_level

Level of verbose information displayed. Default set to '1'.

Examples

## As `save_outputs` is the last step in the pipeline we have to run
## the 'whole machinery' in order to show its functionality. Also take a look
## at the `AutoslideR-Demo` repo on code.roche.com.
library(dplyr, warn.conflicts = FALSE)

data <- list(
  adsl = eg_adsl,
  adae = eg_adae,
  adtte = eg_adtte
)

filters::load_filters(
  yaml_file = system.file("filters.yml", package = "autoslider.core"),
  overwrite = TRUE
)

## For this example the outputs will be saved in a temporary directory. In a
## production run this should be the reporting event's 'output' folder instead.
output_dir <- tempdir()

spec_file <- system.file("spec.yml", package = "autoslider.core")
read_spec(spec_file) %>%
  filter_spec(program == "t_dm_slide") %>%
  generate_outputs(datasets = data) %>%
  decorate_outputs() %>%
  save_outputs(outfolder = output_dir)

Generate flextable for preview first page

Description

Generate flextable for preview first page

Usage

slides_preview(x)

Arguments

x

rtables or data.frame

Examples

# Example 1. preview table
library(dplyr)
adsl <- eg_adsl
t_dm_slide(adsl, "TRT01P", c("SEX", "AGE")) %>% slides_preview()

Adverse event table

Description

Adverse event table

Usage

t_ae_pt_diff_slide(
  adsl,
  adae,
  arm = "TRT01A",
  cutoff = NA,
  split_by_study = FALSE,
  side_by_side = NULL
)

Arguments

adsl

ADSL data set, dataframe

adae

ADAE data set, dataframe

arm

Arm variable, character, "'TRT01A" by default.

cutoff

Cutoff threshold

split_by_study

Split by study, building structured header for tables

side_by_side

"GlobalAsia" or "GlobalAsiaChina" to define the side by side requirement

Value

rtables object

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
adsl <- eg_adsl %>%
  dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
  dplyr::mutate(
    TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
    ATOXGR = AETOXGR
  )
out <- t_ae_pt_diff_slide(adsl, adae, "TRT01A", 2)
print(out)
generate_slides(out, paste0(tempdir(), "/ae_diff.pptx"))

Adverse event table

Description

Adverse event table

Usage

t_ae_pt_slide(
  adsl,
  adae,
  arm = "TRT01A",
  cutoff = NA,
  prune_by_total = FALSE,
  split_by_study = FALSE,
  side_by_side = NULL
)

Arguments

adsl

ADSL data set, dataframe

adae

ADAE data set, dataframe

arm

Arm variable, character, "'TRT01A" by default.

cutoff

Cutoff threshold

prune_by_total

Prune according total column

split_by_study

Split by study, building structured header for tables

side_by_side

A logical value indicating whether to display the data side by side.

Value

rtables object

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
# Example 1
adsl <- eg_adsl %>%
  dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
  dplyr::mutate(
    TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
    ATOXGR = AETOXGR
  )
out <- t_ae_pt_slide(adsl, adae, "TRT01A", 2)
print(out)
generate_slides(out, "ae.pptx")

# Example 2, prune by total column
out2 <- t_ae_pt_slide(adsl, adae, "TRT01A", 25, prune_by_total = TRUE)
print(out2)
generate_slides(out, paste0(tempdir(), "/ae2.pptx"))

Adverse event table

Description

Adverse event table

Usage

t_ae_pt_soc_diff_slide(
  adsl,
  adae,
  arm = "TRT01A",
  cutoff = NA,
  split_by_study = FALSE,
  side_by_side = NULL
)

Arguments

adsl

ADSL data set, dataframe

adae

ADAE data set, dataframe

arm

Arm variable, character, "'TRT01A" by default.

cutoff

Cutoff threshold

split_by_study

Split by study, building structured header for tables

side_by_side

"GlobalAsia" or "GlobalAsiaChina" to define the side by side requirement

Value

rtables object

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
adsl <- eg_adsl %>%
  dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
  dplyr::mutate(
    TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
    ATOXGR = AETOXGR
  )
out <- t_ae_pt_soc_diff_slide(adsl, adae, "TRT01A", 2)
print(out)
generate_slides(out, paste0(tempdir(), "/ae_diff.pptx"))

Adverse event table

Description

Adverse event table

Usage

t_ae_pt_soc_slide(
  adsl,
  adae,
  arm,
  cutoff = NA,
  prune_by_total = FALSE,
  split_by_study = FALSE,
  side_by_side = NULL
)

Arguments

adsl

ADSL data set, dataframe

adae

ADAE data set, dataframe

arm

Arm variable, character

cutoff

Cutoff threshold

prune_by_total

Prune according total column

split_by_study

Split by study, building structured header for tables

side_by_side

"GlobalAsia" or "GlobalAsiaChina" to define the side by side requirement

Value

rtables object

Examples

library(dplyr)
# Example 1
adsl <- eg_adsl %>%
  dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
  dplyr::mutate(
    TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
    ATOXGR = AETOXGR
  )
out <- t_ae_pt_soc_slide(adsl, adae, "TRT01A", 2)
print(out)
generate_slides(out, "ae.pptx")


# Example 2, prune by total column
out2 <- t_ae_pt_soc_slide(adsl, adae, "TRT01A", 25, prune_by_total = TRUE)
print(out2)
generate_slides(out2, paste0(tempdir(), "/ae2.pptx"))

Adverse event table

Description

Adverse event table

Usage

t_ae_slide(
  adsl,
  adae,
  arm = "TRT01A",
  split_by_study = FALSE,
  side_by_side = NULL
)

Arguments

adsl

ADSL data set, dataframe

adae

ADAE data set, dataframe

arm

Arm variable, character, "'TRT01A" by default.

split_by_study

Split by study, building structured header for tables

side_by_side

should table be displayed side by side

Value

rtables object

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
adsl <- eg_adsl %>%
  dplyr::mutate(TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")))
adae <- eg_adae %>%
  dplyr::mutate(
    TRT01A = factor(TRT01A, levels = c("A: Drug X", "B: Placebo")),
    ATOXGR = AETOXGR
  )
out <- t_ae_slide(adsl, adae, "TRT01A")
print(out)
generate_slides(out, paste0(tempdir(), "/ae.pptx"))

Adverse event summary table

Description

Adverse event summary table

Usage

t_ae_summ_slide(
  adsl,
  adae,
  arm = "TRT01A",
  dose_adjust_flags = NA,
  dose_adjust_labels = NA,
  gr34_highest_grade_only = TRUE
)

Arguments

adsl

ADSL dataset, dataframe

adae

ADAE dataset, dataframe

arm

Arm variable, character, "'TRT01A" by default.

dose_adjust_flags

Character or a vector of characters. Each character is a variable name in adae dataset. These variables are Logical vectors which flag AEs leading to dose adjustment, such as drug discontinuation, dose interruption and reduction. The flag can be related to any drug, or a specific drug.

dose_adjust_labels

Character or a vector of characters. Each character represents a label displayed in the AE summary table (e.g. AE leading to discontinuation from drug X). The order of the labels should match the order of variable names in dose_adjust_flags.

gr34_highest_grade_only

A logical value. Default is TRUE, such that only patients with the highest AE grade as 3 or 4 are included for the count of the "Grade 3-4 AE" and "Treatment-related Grade 3-4 AE" ; set it to FALSE if you want to include patients with the highest AE grade as 5.

Value

an rtables object

Examples

library(dplyr)
ADSL <- eg_adsl
ADAE <- eg_adae

ADAE <- ADAE %>%
  dplyr::mutate(ATOXGR = AETOXGR)
t_ae_summ_slide(adsl = ADSL, adae = ADAE)

# add flag for ae leading to dose reduction
ADAE$reduce_flg <- ifelse(ADAE$AEACN == "DOSE REDUCED", TRUE, FALSE)
t_ae_summ_slide(
  adsl = ADSL, adae = ADAE,
  dose_adjust_flags = c("reduce_flg"),
  dose_adjust_labels = c("AE leading to dose reduction of drug X")
)
# add flgs for ae leading to dose reduction, drug withdraw and drug interruption
ADAE$withdraw_flg <- ifelse(ADAE$AEACN == "DRUG WITHDRAWN", TRUE, FALSE)
ADAE$interrup_flg <- ifelse(ADAE$AEACN == "DRUG INTERRUPTED", TRUE, FALSE)
out <- t_ae_summ_slide(
  adsl = ADSL, adae = ADAE, arm = "TRT01A",
  dose_adjust_flags = c("withdraw_flg", "reduce_flg", "interrup_flg"),
  dose_adjust_labels = c(
    "AE leading to discontinuation from drug X",
    "AE leading to drug X reduction",
    "AE leading to drug X interruption"
  )
)
print(out)
generate_slides(out, paste0(tempdir(), "/ae_summary.pptx"))

Table of AEs of Special Interest adapted from https://insightsengineering.github.io/tlg-catalog/stable/tables/adverse-events/aet01_aesi.html

Description

Table of AEs of Special Interest adapted from https://insightsengineering.github.io/tlg-catalog/stable/tables/adverse-events/aet01_aesi.html

Usage

t_aesi_slide(adsl, adae, aesi, arm = "ACTARM", grad_var = "AETOXGR")

Arguments

adsl

ADSL data set, dataframe

adae

ADAE data set, dataframe.

aesi

AESI variable which will act as a filter to select the rows required to create the table. An example of AESI variable is CQ01NAM.

arm

Arm variable, character, '"ACTARM"' by default.

grad_var

Grading variable, character, '"AETOXGR"' by default.

Value

rtables object

Author(s)

Kai Xiang Lim ('limk43')

Examples

library(dplyr)
adsl <- eg_adsl
adae <- eg_adae
adae_atoxgr <- adae %>% dplyr::mutate(ATOXGR = AETOXGR)
t_aesi_slide(adsl, adae, aesi = "CQ01NAM")
t_aesi_slide(adsl, adae, aesi = "CQ01NAM", arm = "ARM", grad_var = "AESEV")
t_aesi_slide(adsl, adae_atoxgr, aesi = "CQ01NAM", grad_var = "ATOXGR")

Death table

Description

Death table

Usage

t_dd_slide(adsl, arm = "TRT01A", split_by_study = FALSE, side_by_side = NULL)

Arguments

adsl

ADSL data set, dataframe

arm

Arm variable, character, "'TRT01A" by default.

split_by_study

Split by study, building structured header for tables

side_by_side

used for studies in China. "GlobalAsia" or "GlobalAsiaChina" to define the side by side requirement.

Value

rtables object

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
adsl <- eg_adsl %>% preprocess_t_dd()
out1 <- t_dd_slide(adsl, "TRT01A")
print(out1)
generate_slides(out1, paste0(tempdir(), "/dd.pptx"))

out2 <- t_dd_slide(adsl, "TRT01A", split_by_study = TRUE)
print(out2)

Demographic table

Description

Demographic table

Usage

t_dm_slide(
  adsl,
  arm = "TRT01P",
  vars = c("AGE", "SEX", "RACE"),
  stats = c("median", "range", "count_fraction"),
  split_by_study = FALSE,
  side_by_side = NULL
)

Arguments

adsl

ADSL data set, dataframe

arm

Arm variable, character, "'TRT01P" by default.

vars

Characters of variables

stats

see '.stats' from [tern::analyze_vars()]

split_by_study

Split by study, building structured header for tables

side_by_side

"GlobalAsia" or "GlobalAsiaChina" to define the side by side requirement

Value

rtables object

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
adsl <- eg_adsl
out1 <- t_dm_slide(adsl, "TRT01P", c("SEX", "AGE", "RACE", "ETHNIC", "COUNTRY"))
print(out1)
generate_slides(out1, paste0(tempdir(), "/dm.pptx"))

out2 <- t_dm_slide(adsl, "TRT01P", c("SEX", "AGE", "RACE", "ETHNIC", "COUNTRY"),
  split_by_study = TRUE
)
print(out2)

DOR table

Description

DOR table

Usage

t_dor_slide(adsl, adtte, arm = "TRT01P", refgroup = NULL)

Arguments

adsl

ADSL dataset

adtte

ADTTE dataset

arm

Arm variable, character, "'TRT01P" by default.

refgroup

Reference group

Note

* Default arm variables are set to '"TRT01A"' for safety output, and '"TRT01P"' for efficacy output

Examples

library(dplyr)
adsl <- eg_adsl %>%
  dplyr::mutate(TRT01P = factor(TRT01P, levels = c("A: Drug X", "B: Placebo", "C: Combination")))
adtte <- eg_adtte %>%
  dplyr::filter(PARAMCD == "OS") %>%
  dplyr::mutate(TRT01P = factor(TRT01P, levels = c("A: Drug X", "B: Placebo", "C: Combination")))
out <- t_dor_slide(adsl, adtte)
print(out)
generate_slides(out, paste0(tempdir(), "/dor.pptx"))

Add decorated flextable to slides

Description

Add decorated flextable to slides

Usage

table_to_slide(
  ppt,
  content,
  decor = TRUE,
  table_loc = ph_location_type("body"),
  ...
)

Arguments

ppt

Slide

content

Content to be added

decor

Should table be decorated

table_loc

Table location

...

additional arguments

Value

Slide with added content


Convert list of numbers to vectors

Description

Convert list of numbers to vectors

Usage

to_vector(num_list)

Arguments

num_list

list of numbers


Format of xx.xx (xx.x)

Description

Format of xx.xx (xx.x)

Usage

trim_perc(x, output)

Arguments

x

input array

output

output handle


Format of xx.xx (xx.xx)

Description

Format of xx.xx (xx.xx)

Usage

trim_perc1(x, output)

Arguments

x

input array

output

output handle