Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -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 <me@nanx.me>
Description: A collection of 'ggplot2' color palettes inspired by
Expand All @@ -30,5 +31,5 @@ Suggests:
rmarkdown
VignetteBuilder: knitr
Encoding: UTF-8
RoxygenNote: 7.3.1
RoxygenNote: 7.3.2
Roxygen: list(markdown = TRUE)
58 changes: 58 additions & 0 deletions R/staticimports.R
Original file line number Diff line number Diff line change
@@ -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, ...)
}
})
75 changes: 5 additions & 70 deletions R/utils.R
Original file line number Diff line number Diff line change
@@ -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
# <https://github.com/rstudio/shiny>.
#
# For the original version of these functions, please see:
# <https://github.com/rstudio/shiny/blob/v1.8.0/R/staticimports.R>.
#
# The shiny package is licensed under the GNU General Public License version 3.
# For more details on the license, see
# <https://github.com/rstudio/shiny/blob/main/LICENSE>.
# @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")
3 changes: 2 additions & 1 deletion man/ggsci-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading