diff --git a/DESCRIPTION b/DESCRIPTION index e0d3738..e86ad04 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -3,12 +3,13 @@ Type: Package Title: Scientific Journal and Sci-Fi Themed Color Palettes for 'ggplot2' Version: 3.2.0 Authors@R: c( - person("Nan", "Xiao", email = "me@nanx.me", role = c("aut", "cre"), + person("Nan", "Xiao", email = "me@nanx.me", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-0250-5673")), person("Joshua", "Cook", email = "joshuacook0023@gmail.com", role = "ctb"), person("Clara", "Jégousse", email = "cat3@hi.is", role = "ctb"), person("Hui", "Chen", email = "huichen@zju.edu.cn", role = "ctb"), - person("Miaozhu", "Li", email = "miaozhu.li@duke.edu", role = "ctb") + person("Miaozhu", "Li", email = "miaozhu.li@duke.edu", role = "ctb"), + person("Winston", "Chang", role = c("ctb", "cph"), comment = "staticimports.R") ) Maintainer: Nan Xiao Description: A collection of 'ggplot2' color palettes inspired by @@ -30,5 +31,5 @@ Suggests: rmarkdown VignetteBuilder: knitr Encoding: UTF-8 -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) diff --git a/R/staticimports.R b/R/staticimports.R new file mode 100644 index 0000000..14765bc --- /dev/null +++ b/R/staticimports.R @@ -0,0 +1,58 @@ +# Generated by staticimports; do not edit by hand. +# ====================================================================== +# Imported from pkg:staticimports +# ====================================================================== + +get_package_version <- function(pkg) { + # `utils::packageVersion()` can be slow, so first try the fast path of + # checking if the package is already loaded. + ns <- .getNamespace(pkg) + if (is.null(ns)) { + utils::packageVersion(pkg) + } else { + as.package_version(ns$.__NAMESPACE__.$spec[["version"]]) + } +} + +is_installed <- function(pkg, version = NULL) { + installed <- isNamespaceLoaded(pkg) || nzchar(system_file_cached(package = pkg)) + + if (is.null(version)) { + return(installed) + } + + if (!is.character(version) && !inherits(version, "numeric_version")) { + # Avoid https://bugs.r-project.org/show_bug.cgi?id=18548 + alert <- if (identical(Sys.getenv("TESTTHAT"), "true")) stop else warning + alert("`version` must be a character string or a `package_version` or `numeric_version` object.") + + version <- numeric_version(sprintf("%0.9g", version)) + } + + installed && isTRUE(get_package_version(pkg) >= version) +} + +# A wrapper for `system.file()`, which caches the package path because +# `system.file()` can be slow. If a package is not installed, the result won't +# be cached. +system_file_cached <- local({ + pkg_dir_cache <- character() + + function(..., package = "base") { + if (!is.null(names(list(...)))) { + stop("All arguments other than `package` must be unnamed.") + } + + not_cached <- is.na(match(package, names(pkg_dir_cache))) + if (not_cached) { + pkg_dir <- system.file(package = package) + if (nzchar(pkg_dir)) { + pkg_dir_cache[[package]] <<- pkg_dir + } + } else { + pkg_dir <- pkg_dir_cache[[package]] + } + + file.path(pkg_dir, ...) + } +}) diff --git a/R/utils.R b/R/utils.R index 9a244f8..cf4e2e4 100644 --- a/R/utils.R +++ b/R/utils.R @@ -1,71 +1,6 @@ -# These functions: -# - `is_installed()` -# - `get_package_version()` -# - `system_file_cached()` -# were sourced from the shiny package version 1.8.0, available at -# . -# -# For the original version of these functions, please see: -# . -# -# The shiny package is licensed under the GNU General Public License version 3. -# For more details on the license, see -# . +# @staticimports pkg:staticimports +# is_installed -is_installed <- function(pkg, version = NULL) { - installed <- isNamespaceLoaded(pkg) || nzchar(system_file_cached(package = pkg)) - - if (is.null(version)) { - return(installed) - } - - if (!is.character(version) && !inherits(version, "numeric_version")) { - # Avoid https://bugs.r-project.org/show_bug.cgi?id=18548 - alert <- if (identical(Sys.getenv("TESTTHAT"), "true")) stop else warning - alert("`version` must be a character string or a `package_version` or `numeric_version` object.") - - version <- numeric_version(sprintf("%0.9g", version)) - } - - installed && isTRUE(get_package_version(pkg) >= version) -} - -get_package_version <- function(pkg) { - # `utils::packageVersion()` can be slow, so first try the fast path of - # checking if the package is already loaded. - ns <- .getNamespace(pkg) - if (is.null(ns)) { - utils::packageVersion(pkg) - } else { - as.package_version(ns$.__NAMESPACE__.$spec[["version"]]) - } -} - -# A wrapper for `system.file()`, which caches the package path because -# `system.file()` can be slow. If a package is not installed, the result won't -# be cached. -system_file_cached <- local({ - pkg_dir_cache <- character() - - function(..., package = "base") { - if (!is.null(names(list(...)))) { - stop("All arguments other than `package` must be unnamed.") - } - - not_cached <- is.na(match(package, names(pkg_dir_cache))) - if (not_cached) { - pkg_dir <- system.file(package = package) - if (nzchar(pkg_dir)) { - pkg_dir_cache[[package]] <<- pkg_dir - } - } else { - pkg_dir <- pkg_dir_cache[[package]] - } - - file.path(pkg_dir, ...) - } -}) - -is_ggplot2_350 <- function() { - is_installed("ggplot2", version = "3.5.0") -} +#' Check if the installed ggplot2 is newer than 3.5.0 +#' @noRd +is_ggplot2_350 <- function() is_installed("ggplot2", version = "3.5.0") diff --git a/man/ggsci-package.Rd b/man/ggsci-package.Rd index 0de4808..d5f9fce 100644 --- a/man/ggsci-package.Rd +++ b/man/ggsci-package.Rd @@ -20,7 +20,7 @@ Useful links: } \author{ -\strong{Maintainer}: Nan Xiao \email{me@nanx.me} (\href{https://orcid.org/0000-0002-0250-5673}{ORCID}) +\strong{Maintainer}: Nan Xiao \email{me@nanx.me} (\href{https://orcid.org/0000-0002-0250-5673}{ORCID}) [copyright holder] Other contributors: \itemize{ @@ -28,6 +28,7 @@ Other contributors: \item Clara Jégousse \email{cat3@hi.is} [contributor] \item Hui Chen \email{huichen@zju.edu.cn} [contributor] \item Miaozhu Li \email{miaozhu.li@duke.edu} [contributor] + \item Winston Chang (staticimports.R) [contributor, copyright holder] } }