-
Notifications
You must be signed in to change notification settings - Fork 31
Open
Description
Hi
While searching for other information in this package, I came across the function that reports the pandoc version. I’d like to clarify why we are using isNamespaceLoaded() and whether it might be preferable to check instead if {rmarkdown} is installed.
Here is an example that illustrates the reason for my question. Start in a fresh R session and run:
get_pandoc_version <- function() {
if (isNamespaceLoaded("rmarkdown")) {
ver <- rmarkdown::find_pandoc()
if (is.null(ver$dir)) {
"NA (via rmarkdown)"
} else {
paste0(ver$version, " @ ", ver$dir, "/ (via rmarkdown)")
}
} else {
path <- Sys.which("pandoc")
if (path == "") {
"NA"
} else {
ver <- parse_pandoc_version(path)
paste0(ver, " @ ", path)
}
}
}
parse_pandoc_version <- function(path) {
tryCatch(
{
out <- system2(path, "--version", stdout = TRUE)[1]
last(strsplit(out, " ", fixed = TRUE)[[1]])
},
error = function(e) "NA"
)
}
Now, i.e., in a session where {rmarkdown} has not been loaded/attached:
> get_pandoc_version()
[1] "NA"
With and after calling rmarkdown::find_pandoc():
> rmarkdown::find_pandoc()
$version
[1] ‘3.6.3’
$dir
[1] "c:\\Program Files\\Positron\\resources\\app\\quarto\\bin\\tools"
> get_pandoc_version()
[1] "3.6.3 @ c:\\Program Files\\Positron\\resources\\app\\quarto\\bin\\tools/ (via rmarkdown)"
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels