Why can't I knit my RMarkdown file with the dlookr package in the source?

76 Views Asked by At

I am using the dlookr package in my project and cannot knit my RMarkdown file while the code for installing and loading the dlookr package is in the source. This is the error I am getting:

Quitting from lines 12-27 [setup] (Final-Project.Rmd)
Error:
! package or namespace load failed for 'dlookr':
 .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(dlookr)
 2. base::tryCatch(...)
 3. base (local) tryCatchList(expr, classes, parentenv, handlers)
 4. base (local) tryCatchOne(expr, names, parentenv, handlers[[1L]])
 5. value[[3L]](cond)
Execution halted"

The code in lines 12-27 is just different packages I am loading. Here is a screenshot of the code chunk: enter image description here

I tried solutions posted here and here. I checked my Global options and my mirror is already set to "Global (CDN) - RStudio", nothing in my secondary repositories section. Also, I tried the various commands suggested by R but still cannot seem to knit my file.

1

There are 1 best solutions below

1
user2554330 On

That looks like a bug in kableExtra, which is being loaded because dlookr imports it.

kableExtra:::.onLoad() has this test:

if (!is.null(rmarkdown::metadata$output) && rmarkdown::metadata$output %in% 
        c("ioslides_presentation", "slidy_presentation", "gitbook", 
            "bookdown::gitbook", "radix_article", "radix::radix_article", 
            "distill_article", "distill::distill_article")) {
        options(kableExtra.html.bsTable = TRUE)
    }

In your document, rmarkdown::metadata$output contains more than one entry, so rmarkdown::metadata$output %in% ... ends up containing more than one value.

The workaround for this bug is simply to make sure the output section in your YAML at the start of your document only contains one output format. For example, these would be fine:

output: html_document

or

output: 
  html_document:
    toc: true

but this would trigger the error:

output:
  html_document: default
  pdf_document: default