content <- data.frame(
USUBJID = c("S1", "S1", "S1", "S2", "S2", "S2", "S3"),
ARM = c("A", "A", "B", "A", "A", "B", "A"),
VAL = round(rnorm(7), 2)
)
ft <- flextable::as_flextable(content)
ft <- flextable::theme_booktabs(ft)
# Define separators: line, space, NA, line, space, NA, NA
sep_ctrl <- c("-", " ", NA, "-", " ", NA, NA)
ft_modified <- add_flextable_separators(ft, sep_ctrl)
print(ft_modified)
# Example: All NA - should return original ft
ft_all_na <- add_flextable_separators(ft, rep(NA, 7))
identical(ft, ft_all_na) # Should be TRUE
# Example: Invalid character - should throw error
tryCatch(
add_flextable_separators(ft, c("-", "x", NA, "-", " ", NA, NA)),
error = function(e) print(e)
)
Run the code above in your browser using DataLab