https://github.com/cran/pkgdown
Raw File
Tip revision: 391644d9199141600dab70b9b10342ec07eee299 authored by Hadley Wickham on 02 June 2018, 21:10:23 UTC
version 1.1.0
Tip revision: 391644d
pkgdown.R
#' @importFrom magrittr %>%
#' @importFrom roxygen2 roxygenise
#' @importFrom R6 R6Class
#' @import rlang
#' @import fs
NULL

#' Determine if code is executed by pkgdown
#'
#' This is occassionally useful when you need different behaviour by
#' pkgdown and regular documentation.
#'
#' @export
#' @examples
#' in_pkgdown()
in_pkgdown <- function() {
  identical(Sys.getenv("IN_PKGDOWN"), "true")
}

set_pkgdown_env <- function(x) {
  old <- Sys.getenv("IN_PKGDOWN")
  Sys.setenv("IN_PKGDOWN" = x)
  invisible(old)
}

scoped_in_pkgdown <- function(scope = parent.frame()) {
  old <- set_pkgdown_env("true")
  defer(set_pkgdown_env(old), scope = scope)
}

back to top