Skip to content

Commit

Permalink
add feature of exporting PDF
Browse files Browse the repository at this point in the history
  • Loading branch information
kaigu1990 committed May 9, 2024
1 parent b723152 commit 7fea001
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
18 changes: 16 additions & 2 deletions R/pkg-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ print.or_ci <- function(x, ...) {
#' @exportS3Method
#' @keywords internal
#' @param fm (`string`)\cr string of unit for survival time.
print.s_survival <- function(x, fm = "months", ...) {
#' @param export_pdf (`logical`)\cr whether to export PDF to the current directory.
print.s_survival <- function(x, fm = "months", export_pdf = FALSE, ...) {
cat("Surv formula: ", x$params$formula, "\n", sep = "")
grp <- unique(x$surv$quantile$group)
cat("Group by: ", paste(grp, collapse = ", "), "\n", sep = "")
Expand Down Expand Up @@ -408,13 +409,20 @@ print.s_survival <- function(x, fm = "months", ...) {
build_table(df)
print(result)

if (export_pdf) {
tf <- tempfile(pattern = "t_surv_", tmpdir = getwd(), fileext = ".pdf")
file <- rtables::export_as_pdf(result, file = tf)
print(file$file)
}

invisible(x)
}

#' @describeIn s_get_coxph prints survival analysis summary from `coxph`.
#' @exportS3Method
#' @keywords internal
print.s_coxph <- function(x, ...) {
#' @param export_pdf (`logical`)\cr whether to export PDF to the current directory.
print.s_coxph <- function(x, export_pdf = FALSE, ...) {
cat("Surv formula: ", x$params$formula, "\n", sep = "")
grp <- x$params$group
cat("Group by: ", paste(grp, collapse = ", "), "\n", sep = "")
Expand Down Expand Up @@ -496,6 +504,12 @@ print.s_coxph <- function(x, ...) {
build_table(df)
print(result)

if (export_pdf) {
tf <- tempfile(pattern = "t_coxph_", tmpdir = getwd(), fileext = ".pdf")
file <- rtables::export_as_pdf(result, file = tf)
print(file$file)
}

invisible(x)
}

Expand Down
4 changes: 3 additions & 1 deletion man/s_get_coxph.Rd

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

4 changes: 3 additions & 1 deletion man/s_get_survfit.Rd

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

0 comments on commit 7fea001

Please sign in to comment.