Skip to content

Commit

Permalink
Fix built-in data to use true CGMP colors; add ability to retrieve Ma…
Browse files Browse the repository at this point in the history
…crostrat colors
  • Loading branch information
willgearty committed Mar 21, 2024
1 parent 657f348 commit 5307477
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 15 deletions.
24 changes: 17 additions & 7 deletions R/get_scale_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@
#'
#' This function takes a name of a geological timescale and returns data for the
#' timescale. Valid names include those of built-in `data.frames` ([periods()],
#' [epochs()], [stages()], [eons()], or [eras()]),
#' partial matches of those names (e.g., "per" or "stage"),
#' and exact matches to those hosted by Macrostrat (see full list here:
#' <https://macrostrat.org/api/defs/timescales?all>).
#' [epochs()], [stages()], [eons()], or [eras()]), partial matches of those
#' names (e.g., "per" or "stage"), and exact matches to those hosted by
#' Macrostrat (see full list here:
#' <https://macrostrat.org/api/defs/timescales?all>). Note that the colors in
#' the built-in `data.frames` are according to the Commission for the Geological
#' Map of the World. If you would like to obtain custom Macrostrat colors that
#' are better for mapping, you should specify the full name of a timescale
#' (e.g., "international periods") and set `true_colors` to `FALSE`. Note that
#' these colors only vary for the Precambrian.
#'
#' @param name The name of the desired timescale.
#' @return A `data.frame` with the following columns:
#' \item{name}{the names of the time intervals.}
#' @param true_colors Return original international time scale colors? (as
#' opposed to custom Macrostrat plotting colors)
#' @return A `data.frame` with the following columns: \item{name}{the names of
#' the time intervals.}
#' \item{max_age}{the oldest boundaries of the time intervals, in millions of
#' years.}
#' \item{min_age}{the youngest boundaries of the time intervals, in millions
Expand All @@ -21,7 +28,7 @@
#' @importFrom utils read.csv
#' @importFrom curl nslookup
#' @export
get_scale_data <- function(name) {
get_scale_data <- function(name, true_colors = TRUE) {
check_required(name)
possible_names <- c("periods", "epochs", "stages", "eras", "eons")
name_match <- charmatch(name, possible_names)
Expand Down Expand Up @@ -56,6 +63,9 @@ get_scale_data <- function(name) {
)# nocov end
URL <- url(paste0("https://macrostrat.org/api/v2/defs/intervals",
"?format=csv&timescale=", gsub(" ", "%20", name)))
if (true_colors) {
URL <- paste0(URL, "&true_colors=true")
}
raw_dat <- tryCatch(
{
read.csv(URL, header = TRUE, stringsAsFactors = FALSE)
Expand Down
2 changes: 1 addition & 1 deletion data-raw/ICS_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ for (int_type in names(int_types)) {
# Get ICS data from Macrostrat
raw_dat <- read.csv(url(paste0("https://macrostrat.org/api/v2/defs/intervals",
"?format=csv&timescale=international%20",
int_types[int_type])),
int_types[int_type], "&true_colors=true")),
stringsAsFactors = FALSE)
clean_dat <- raw_dat[, c("name", "b_age", "t_age", "abbrev", "color")]
colnames(clean_dat) <- c("name", "max_age", "min_age", "abbr", "color")
Expand Down
Binary file modified data/eons.rda
Binary file not shown.
Binary file modified data/eras.rda
Binary file not shown.
Binary file modified data/periods.rda
Binary file not shown.
Binary file modified data/stages.rda
Binary file not shown.
22 changes: 15 additions & 7 deletions man/get_scale_data.Rd

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

0 comments on commit 5307477

Please sign in to comment.