Closed lchensigma closed 7 months ago
hi @lchensigma , can you provide us with a reproducible example? Thanks!
here is the code. Thank you. Also the export_as_pdf
only produce the empty PDF file if code is in RMarkDown.
library(tern)
library(scda)
library(dplyr)
library(tidyr)
adsl <- synthetic_cdisc_dataset("latest", "adsl")
advs <- synthetic_cdisc_dataset("latest", "advs")
adsub <- synthetic_cdisc_dataset("latest", "adsub")
# Ensure character variables are converted to factors and empty strings and NAs are explicit missing levels.
adsl <- df_explicit_na(adsl)
advs <- df_explicit_na(advs)
adsub <- df_explicit_na(adsub)
# Change description in variable SEX.
adsl <- adsl %>%
mutate(
SEX = factor(case_when(
SEX == "M" ~ "Male",
SEX == "F" ~ "Female",
SEX == "U" ~ "Unknown",
SEX == "UNDIFFERENTIATED" ~ "Undifferentiated"
)),
AGEGR1 = factor(
case_when(
between(AGE, 18, 40) ~ "18-40",
between(AGE, 41, 64) ~ "41-64",
AGE > 64 ~ ">=65"
),
levels = c("18-40", "41-64", ">=65")
),
BMRKR1_CAT = factor(
case_when(
BMRKR1 < 3.5 ~ "LOW",
BMRKR1 >= 3.5 & BMRKR1 < 10 ~ "MEDIUM",
BMRKR1 >= 10 ~ "HIGH"
),
levels = c("LOW", "MEDIUM", "HIGH")
)
) %>%
var_relabel(
BMRKR1_CAT = "Biomarker 1 Categories"
)
# The developer needs to do pre-processing to add necessary variables based on ADVS to analysis dataset.
# Obtain SBP, DBP and weight.
get_param_advs <- function(pname, plabel) {
ds <- advs %>%
filter(PARAM == plabel & AVISIT == "BASELINE") %>%
select(USUBJID, AVAL)
colnames(ds) <- c("USUBJID", pname)
ds
}
# The developer needs to do pre-processing to add necessary variables based on ADSUB to analysis dataset.
# Obtain baseline BMI (BBMISI).
get_param_adsub <- function(pname, plabel) {
ds <- adsub %>%
filter(PARAM == plabel) %>%
select(USUBJID, AVAL)
colnames(ds) <- c("USUBJID", pname)
ds
}
adsl <- adsl %>%
left_join(get_param_advs("SBP", "Systolic Blood Pressure"), by = "USUBJID") %>%
left_join(get_param_advs("DBP", "Diastolic Blood Pressure"), by = "USUBJID") %>%
left_join(get_param_advs("WGT", "Weight"), by = "USUBJID") %>%
left_join(get_param_adsub("BBMISI", "Baseline BMI"), by = "USUBJID")
vars <- c("AGE", "AGEGR1", "SEX", "ETHNIC", "RACE", "BMRKR1")
var_labels <- c(
"Age (yr)",
"Age Group",
"Sex",
"Ethnicity",
"Race",
"Continous Level Biomarker 1"
)
result <- basic_table(show_colcounts = TRUE) %>%
split_cols_by(var = "ACTARM") %>%
add_overall_col("All Patients") %>%
analyze_vars(
vars = vars,
var_labels = var_labels
) %>%
build_table(adsl)
result
export_as_rtf(result, file="test.rtf", landscape = TRUE)
export_as_pdf(result%>% prune_table() , file="test.pdf", landscape = TRUE)
If I check the result of export_as_rtf
from your example indentation is still present
Thank you. I think it was fixed now.
Summary
when use export_as_rtf to output rtf with rtables, indents was lost.
R session info
OS / Environment