From b67ac7126be5ed895bfead32e77086bfd8dfae9e Mon Sep 17 00:00:00 2001 From: Vincent Arel-Bundock Date: Mon, 15 Jan 2024 11:39:00 -0500 Subject: [PATCH] check_dependency bug and markdown print --- R/print.R | 8 ++++++-- R/sanity.R | 4 ++-- R/tt_markdown.R | 7 +++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/R/print.R b/R/print.R index b9c62f8b..695676ee 100644 --- a/R/print.R +++ b/R/print.R @@ -28,19 +28,23 @@ knit_print.tinytable <- function(x, ...) { print.tinytable <- function(x, ...) { m <- meta(x) - if (m$output %in% c("markdown", "latex")) { + if (m$output == "latex") { out <- x class(out) <- "character" cat("\n") cat(out) cat("\n") + } else if (m$output == "markdown") { + cat("\n") + cat(x, sep = "\n") + } else if (m$output == "html") { dir <- tempfile() dir.create(dir) htmlFile <- file.path(dir, "index.html") cat(x, file = htmlFile) - if (check_dependency("rstudioapi") && rstudioapi::isAvailable()) { + if (isTRUE(check_dependency("rstudioapi")) && rstudioapi::isAvailable()) { rstudioapi::viewer(htmlFile) } else { utils::browseURL(htmlFile) diff --git a/R/sanity.R b/R/sanity.R index 37dd3a5f..0728f37e 100644 --- a/R/sanity.R +++ b/R/sanity.R @@ -8,7 +8,7 @@ sanitize_output <- function(output) { # default output format if (is.null(output)) { - in_rstudio <- interactive() && check_dependency("rstudioapi") && rstudioapi::isAvailable() + in_rstudio <- interactive() && isTRUE(check_dependency("rstudioapi")) && rstudioapi::isAvailable() out <- getOption("tt_output_default", default = if (in_rstudio) "html" else "markdown") } else { @@ -54,7 +54,7 @@ check_dependency <- function(library_name) { } assert_dependency <- function(library_name){ - flag <- check_dependency(library_name) + flag <- isTRUE(check_dependency(library_name)) if (!isTRUE(flag)) stop(flag, call. = FALSE) return(invisible()) } diff --git a/R/tt_markdown.R b/R/tt_markdown.R index 212c8a27..442fabe9 100644 --- a/R/tt_markdown.R +++ b/R/tt_markdown.R @@ -53,6 +53,9 @@ tt_markdown <- function(tab, caption, ...) { header[[i]] <- align_str_center(header[[i]], nchar(tab[[i]][1])) } tab <- rbind(header, tab) + hrule <- 1 + } else { + hrule <- NULL } # pipes @@ -70,10 +73,6 @@ tt_markdown <- function(tab, caption, ...) { ruler <- sub("\\|-", "|:", ruler) # only first ruler <- gsub("-$", "", ruler) # only first - hrule <- NULL - if (!is.null(colnames(tab))) { - hrule <- 1 - } for (h in hrule) { tab <- append(tab, ruler, after = h) }