Merge pull request #521 from r2evans/fix/517_img_emptydata_class_specline

fix #517, #518, #519
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..14c0ea1 100644
--- a/R/column_spec.R
+++ b/R/column_spec.R
@@ -264,9 +264,9 @@
                                              extra_css)
   }
 
-  if (!is.null(image)) {
+  if (!is.null(image) && (length(image) > 1 || !is.null(image[[1]]))) {
     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]
@@ -539,9 +539,9 @@
                               new_row[column], "\\}")
   }
 
-  if (!is.null(image)) {
+  if (!is.null(image) && (length(image) > 1 || !is.null(image[[1]]))) {
     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/mini_plots.R b/R/mini_plots.R
index e1c65d3..1c15262 100644
--- a/R/mini_plots.R
+++ b/R/mini_plots.R
@@ -46,6 +46,8 @@
     )}))
   }
 
+  if (is.null(x)) return(NULL)
+
   if (is.null(lim)) {
     lim <- base::range(x)
   }
@@ -147,6 +149,8 @@
     )}))
   }
 
+  if (is.null(x)) return(NULL)
+
   if (is.null(lim)) {
     lim <- base::range(x)
     lim[1] <- lim[1] - (lim[2] - lim[1]) / 10
@@ -284,6 +288,8 @@
     }, x, y))
   }
 
+  if (is.null(x)) return(NULL)
+
   if (is.null(y) || !length(y)) {
     y <- x
     x <- seq(0, 1, length.out = length(y))
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)
   }