devtools::load_all()
knitr::opts_chunk$set(fig.path = "man/figures/README-", fig.align = "center")

prioritizrdata: Conservation Planning Datasets

lifecycle R-CMD-check-Ubuntu R-CMD-check-Windows R-CMD-check-macOS Documentation Coverage Status CRAN_Status_Badge

The prioritizrdata R package is a supplemental package that contains example datasets for conservation planning. It is intended to be used alongside the prioritizr R package.

Overview

This package contains the following datasets.

Installation

The latest official version of the prioritizrdata R package can be installed using the following R code.

install.packages("prioritizrdata", repos = "https://cran.rstudio.com/")

Alternatively, the latest development version can be installed using the following code. Please note that while developmental versions may contain additional features not present in the official version, they may also contain coding errors.

if (!require(devtools))
  install.packages("devtools")
devtools::install_github("prioritizr/prioritizrdata")

Citation

Please cite the prioritizrdata R package when using it in publications. To cite the latest official version, please use:

# define helpers
is_rel_version <- function(x) {
  length(strsplit(as.character(x), ".", fixed = TRUE)[[1]]) == 3
}

package_version_year <- function(x) {
  if (x %in% rownames(available.packages())) {
    return(live_package_version_year(x))
  } else {
    return(archive_package_version_year(x))
  }
}

live_package_version_year <- function(x) {
  # fetch data
  d <- paste0("http://cran.r-project.org/web/packages/", x, "/DESCRIPTION")
  d <- read.dcf(url(d))
  c(
    as.character(d[, "Version"]),
    as.character(format(as.POSIXct(d[, "Date/Publication"]), "%Y"))
  )
}

archive_package_version_year <- function(x) {
  # fetch data (copied from remotes R package)
  tf <- tempfile(fileext = ".gz")
  on.exit(unlink(tf), add = TRUE)
  download.file(tf, url = sprintf("%s/src/contrib/Meta/archive.rds", repo))
  con <- gzfile(tf, "rb")
  on.exit(close(con), add = TRUE)
  d <- readRDS(con)[[x]]
  # extract version
  rel_version <- basename(rownames(d))
  rel_version <- sapply(strsplit(rel_version, "_", fixed = TRUE), `[[`, 2)
  rel_version <- sapply(strsplit(rel_version, ".tar", fixed = TRUE), `[[`, 1)
  rel_version <- max(rel_version)
  # extract year
  rel_year <- as.character(max(format(d[, "mtime"], "%Y")))
  # return year version
  c(rel_version, rel_year)
}

# get version numbers and years
dev_version_year <- c(
  as.character(packageDescription("prioritizrdata")$Version),
  format(Sys.time(), "%Y")
)
if (is_rel_version(dev_version_year[[1]])) {
  rel_version_year <- dev_version_year
} else {
  rel_version_year <- package_version_year("prioritizrdata")
}
cat(paste0("> Hanson JO, Schuster R, Morrell N, Strimas-Mackey M, Watts ME, Arcese P, Bennett J, Possingham HP (", rel_version_year[[2]] ,"). prioritizrdata: Conservation Planning Datasets. R package version ", rel_version_year[[1]],". Available at https://CRAN.R-project.org/package=prioritizrdata.\n"))

Alternatively, to cite the latest development version, please use:

cat(paste0("> Hanson JO, Schuster R, Morrell N, Strimas-Mackey M, Watts ME, Arcese P, Bennett J, Possingham HP (", dev_version_year[[2]],"). prioritizrdata: Conservation Planning Datasets. R package version ", dev_version_year[[1]], ". Available at https://github.com/prioritizr/prioritizrdata.\n"))


prioritizr/prioritizrdata documentation built on Aug. 22, 2023, 10:54 p.m.