Thus, the best solution I have found so far is to implement a context analyzer using the RStudio API:
prIsNotebook <- function() { if (!rstudioapi::isAvailable()) { return(FALSE) } ctxt <- rstudioapi::getActiveDocumentContext() if (grepl("\\.Rmd$", ctxt$path)) { return(TRUE) }
I will not check this as an answer, since it is more of a hack than a true solution.
source share