Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

what's the use of the cextra_args element, can we remove it by default? #324

Closed
shajoezhu opened this issue May 17, 2022 · 0 comments
Closed
Labels

Comments

@shajoezhu
Copy link
Collaborator

Original issue reported by Elisabeth_Gruendl at https://overflow.roche.com/t/error-invalid-class-instantiatedcolumninfo-object-invalid-object-for-slot-cextra-args-in-class-instantiatedcolumninfo-got-class-numeric-should-be-or-extend-class-list/10903

library(rtables)
library(dplyr)

df <- tibble(visit = factor(rep(c("24", "52", "76", "104", "116"), times = 2), levels = c("24", "52", "76", "104", "116")),
group = factor(rep(c("Placebo", "Active"), each = 5), levels = c("Placebo", "Active")),
est = c(1, 1.2, 1.4, 1.6, 1.8, 0.9, 1, 1.1, 1.2, 1.3),
est_se = c(.3, .4, .5, .4, .3, .2, .1, .3, .4, .2),
p_value = c(NA, NA, NA, NA, NA, .8758390, .726295, .5397435, .3175389, .1563281),
header_p_value = rep("p-value of difference"))

dummy <- character()

# create first table with information by treatment
s_rbmi_trt <- function(df, .in_ref_col) {
list(
zeile1 = df$est,
zeile2 = df$est_se
)
}

a_rbmi_trt <- make_afun(
s_rbmi_trt,
.labels = c(
zeile1 = "Change from Baseline",
zeile2 = "at Week"
),
.formats = c(
zeile1 = sprintf_format("%.3f "),
zeile2 = "xx.xxx"
),
.indent_mods = c(
zeile1 = 1L,
zeile2 = 1L
)
)

summarize_rbmi_trt <- function(lyt,
...,
table_names = "rbmi_summary",
.stats = NULL,
.formats = NULL,
.indent_mods = NULL,
.labels = NULL) {
afun <- make_afun(
a_rbmi_trt,
.stats = .stats,
.formats = .formats,
.indent_mods = .indent_mods,
.labels = .labels
)
analyze(
lyt = lyt,
vars = "est",
afun = afun,
table_names = table_names,
extra_args = list(...)
)
}

rbmi_trt <- basic_table() %>%
split_cols_by("group", ref_group = levels(df$group)[1]) %>%
split_rows_by("visit", split_label = "Visit", label_pos = "topleft") %>%
summarize_rbmi_trt() %>%
build_table(df)

###############################################

########################

s_rbmi_pval <- function(df) {
list(
zeile1 = df$p_value,
zeile2 = dummy
)
}

a_rbmi_pval <- make_afun(
s_rbmi_pval,
.labels = c(
zeile1 = "Change from Baseline",
zeile2 = "at Week"
),
.formats = c(
zeile1 = "x.xxxx | (<0.0001)"
),
.indent_mods = c(
zeile1 = 1L,
zeile2 = 1L
)
)

summarize_rbmi_pval <- function(lyt,
...,
table_names = "rbmi_summary",
.stats = NULL,
.formats = NULL,
.indent_mods = NULL,
.labels = NULL) {
afun <- make_afun(
a_rbmi_pval,
.stats = .stats,
.formats = .formats,
.indent_mods = .indent_mods,
.labels = .labels
)
analyze(
lyt = lyt,
vars = "est",
afun = afun,
table_names = table_names,
extra_args = list(...)
)
}

rbmi_pval <- basic_table() %>%
split_cols_by("header_p_value") %>%
split_rows_by("visit", split_label = " ", label_pos = "topleft") %>%
summarize_rbmi_pval() %>%
build_table(df %>% filter(group == "Active"))

top_left(rbmi_trt) <- "Visit"
top_left(rbmi_pval) <- "Visit"


rbmi_landscape <- cbind_rtables(rbmi_trt, rbmi_pval)

work around provided by Liming

rbmi_trt1 <- rbmi_trt
rbmi_trt1@col_info@cextra_args <- list()
cbind_rtables(rbmi_trt1, rbmi_pval)

This will remove the cextra_args in that object, so it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant