fix #519, change from 'class' comparison to 'inherits'
diff --git a/R/cell_spec.R b/R/cell_spec.R
index 8a69c1f..5e58b1c 100644
--- a/R/cell_spec.R
+++ b/R/cell_spec.R
@@ -117,10 +117,10 @@
# favor popover over tooltip
if (!is.null(popover)) {
- if (class(popover) != "ke_popover") popover <- spec_popover(popover)
+ if (!inherits(popover, "ke_popover")) popover <- spec_popover(popover)
tooltip_n_popover <- popover
} else if (!is.null(tooltip)) {
- if (class(tooltip) != "ke_tooltip") tooltip <- spec_tooltip(tooltip)
+ if (!inherits(tooltip, "ke_tooltip")) tooltip <- spec_tooltip(tooltip)
tooltip_n_popover <- tooltip
} else {
tooltip_n_popover <- NULL
diff --git a/R/column_spec.R b/R/column_spec.R
index 77f0c69..25d1289 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -266,7 +266,7 @@
if (!is.null(image)) {
image <- image[[1]]
- if (class(image) == "kableExtraInlinePlots") {
+ if (inherits(image, "kableExtraInlinePlots")) {
if (!is.null(image$svg_text)) {
xml_add_child(target_cell, xml2::read_xml(image$svg_text))
} else {
@@ -284,13 +284,13 @@
# favor popover over tooltip
if (!is.null(popover)) {
- if (class(popover) != "ke_popover") popover <- spec_popover(popover)
+ if (!inherits(popover, "ke_popover")) popover <- spec_popover(popover)
popover_list <- attr(popover, 'list')
for (p in names(popover_list)) {
xml_attr(target_cell, p) <- popover_list[p]
}
} else if (!is.null(tooltip)) {
- if (class(tooltip) != "ke_tooltip") tooltip <- spec_tooltip(tooltip)
+ if (!inherits(tooltip, "ke_tooltip")) tooltip <- spec_tooltip(tooltip)
tooltip_list <- attr(tooltip, 'list')
for (t in names(tooltip_list)) {
xml_attr(target_cell, t) <- tooltip_list[t]
@@ -541,7 +541,7 @@
if (!is.null(image)) {
image <- image[[1]]
- if (class(image) == "kableExtraInlinePlots") {
+ if (inherits(image, "kableExtraInlinePlots")) {
new_row[column] <- paste0(
new_row[column],
'\\\\includegraphics\\[width=',
diff --git a/R/kable_as_image.R b/R/kable_as_image.R
index ffe18be..6a0098d 100644
--- a/R/kable_as_image.R
+++ b/R/kable_as_image.R
@@ -67,7 +67,7 @@
table_img_pdf <- try(magick::image_read(paste0(temp_file, ".pdf"),
density = density),
silent = T)
- if (class(table_img_pdf) == "try-error") {
+ if (inherits(table_img_pdf, "try-error")) {
stop("Ghostscript is required to read PDF on windows. ",
"Please download it here: https://ghostscript.com/")
}
diff --git a/R/save_kable.R b/R/save_kable.R
index 974ab70..e1e1636 100644
--- a/R/save_kable.R
+++ b/R/save_kable.R
@@ -167,7 +167,7 @@
table_img_pdf <- try(
magick::image_read(paste0(file_no_ext, ".pdf"),
density = density), silent = T)
- if (class(table_img_pdf) == "try-error") {
+ if (inherits(table_img_pdf, "try-error")) {
stop("We hit an error when trying to use magick to read the generated ",
"PDF file. You may check your magick installation and try to ",
"use magick::image_read to read the PDF file manually. It's also ",
diff --git a/R/xtable2kable.R b/R/xtable2kable.R
index 3c13658..478d6f2 100644
--- a/R/xtable2kable.R
+++ b/R/xtable2kable.R
@@ -25,7 +25,7 @@
#'
#' @export
xtable2kable <- function(x, ...) {
- if (!class(x)[1] == "xtable") {
+ if (!inherits(x, "xtable")) {
warning("x is not an xtable object.")
return(x)
}