diff --git a/NEWS.md b/NEWS.md index 207849fca..122f0306f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -16,6 +16,8 @@ - Resources with URL encoded special characters are now correctly copied to the output directory (thanks, @AshesITR, #622). +- `serve_book()` can now be used without error when rstudioapi is installed but RStudio is not being used (thanks, @jimhester, #637). + # CHANGES IN bookdown VERSION 0.7 ## MAJOR CHANGES diff --git a/R/utils.R b/R/utils.R index 55aa72244..4f6e882e3 100644 --- a/R/utils.R +++ b/R/utils.R @@ -268,7 +268,8 @@ serve_book = function( ) { # when this function is called via the RStudio addin, use the dir of the # current active document - if (missing(dir) && requireNamespace('rstudioapi', quietly = TRUE)) { + if (missing(dir) && requireNamespace('rstudioapi', quietly = TRUE) && + rstudioapi::isAvailable()) { path = rstudioapi::getSourceEditorContext()[['path']] if (!(is.null(path) || path == '')) dir = dirname(path) }