kableExtra bug only when using knit button in RStudio

I am currently unable to load the "kableExtra" package when using the "knit" button in RStudio. The code works fine if I execute it in the console or if I just call "rmarkdown::render" directly.

I reported this bug previously, and the topic was closed after 21 days while I was on vacation out of town. But I now have more information, and I think I can explain what the problem is.

Below is a minimal reproducible example. (Note that I replaced leading spaces with underscores, because the forum software eats the leading white space that is significant in a YAML header.)

title: "My Title"
author: "Kevin R. Coombes"
date: "r Sys.Date()"
output:
__html_document:
____theme: readable
____highlight: kate
__pdf_document:
____highlight: kate

We need these packages from the R library:

cat("class:", class(rmarkdown::metadata$output), 
    "\n\tlength:", length(rmarkdown::metadata$output), "\n",
    file = stderr())
library(kableExtra)

And here is the error message (including the output I wrote using cat):

class: list
length: 2

Quitting from lines 15-19 [packs] (00-kEbug.Rmd)
Error:
! package or namespace load failed for 'kableExtra':
.onLoad failed in loadNamespace() for 'kableExtra', details:
call: !is.null(rmarkdown::metadata$output) && rmarkdown::metadata$output %in%
error: 'length = 2' in coercion to 'logical(1)'
Backtrace:

  1. base::library(kableExtra)
  2. base::tryCatch(...)
  3. base (local) tryCatchList(expr, classes, parentenv, handlers)
  4. base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
  5. value[3L]
    Execution halted

As you can see, the value of rmarkdown::metadata$output is a list of length 2, where each element is of length greater than 1, (since the YAML header specifies multiple options for two different kinds of output documents). The bug arises from the change in R 4.3 that asys you need a logical of length exactly 1 in a conditional "if" statement, and the test here is being performed on a longer list.

Note that if you run this code in the console, the value of rmarkdown::metadata$output is simply NULL, so it doesn't cause an error/

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.