Skip to content

Commit

Permalink
check_dependency bug and markdown print
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 15, 2024
1 parent 2989ef4 commit b67ac71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
8 changes: 6 additions & 2 deletions R/print.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions R/sanity.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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())
}
Expand Down
7 changes: 3 additions & 4 deletions R/tt_markdown.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down

0 comments on commit b67ac71

Please sign in to comment.