Skip to content

Commit

Permalink
defensive programming
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentarelbundock committed Jan 24, 2024
1 parent eac88b5 commit 02e056f
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion R/finalize_bootstrap.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

finalize_bootstrap <- function(x) {
if (meta(x)$output != "html") return(x)
if (!isTRUE(meta(x)$output == "html")) return(x)
out <- gsub(
"$tinytable_BOOTSTRAP_CLASS",
"table",
Expand Down
2 changes: 1 addition & 1 deletion R/finalize_grid.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

finalize_grid <- function(x) {
if (meta(x)$output != "markdown") return(x)
if (!isTRUE(meta(x)$output == "markdown")) return(x)

out <- x

Expand Down
4 changes: 2 additions & 2 deletions R/format_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ format_tt_lazy <- function(x,
if (isTRUE(markdown)) {
assert_dependency("markdown")
for (col in j) {
if (meta(x)$output == "html") {
if (isTRUE(meta(x)$output == "html")) {
fun <- function(x) {
out <- trimws(markdown::mark_html(text = x, template = FALSE))
out <- sub("<p>", "", out, fixed = TRUE)
out <- sub("</p>", "", out, fixed = TRUE)
return(out)
}
x[, col] <- sapply(x[, col], fun)
} else if (meta(x)$output == "latex") {
} else if (isTRUE(meta(x)$output == "latex")) {
fun <- function(x) trimws(markdown::mark_latex(text = x, template = FALSE))
x[, col] <- sapply(x[, col], fun)
}
Expand Down
6 changes: 3 additions & 3 deletions R/plot_tt.R
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,18 @@ plot_tt_lazy <- function(x,
}
}

if (meta(x)$output == "latex") {
if (isTRUE(meta(x)$output == "latex")) {
cell <- "\\includegraphics[height=%sem]{%s}"
cell <- sprintf(cell, height, images)

} else if (meta(x)$output == "html") {
} else if (isTRUE(meta(x)$output == "html")) {
cell <- ifelse(
grepl("^http", trimws(images)),
'<img src="%s" style="height: %sem;">',
'<img src="./%s" style="height: %sem;">')
cell <- sprintf(cell, images, height)

} else if (meta(x)$output == "markdown") {
} else if (isTRUE(meta(x)$output == "markdown")) {
cell <- '![](%s)'
cell <- sprintf(cell, images)

Expand Down

0 comments on commit 02e056f

Please sign in to comment.