Skip to content

Commit

Permalink
feat: ✨ added functions to get R and Rstudio versions
Browse files Browse the repository at this point in the history
Closes #49 closes #3 closes #1
  • Loading branch information
lwjohnst86 committed Dec 15, 2024
1 parent 6f36fde commit a76b91a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 9 deletions.
50 changes: 50 additions & 0 deletions R/get-versions.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#' Get a list of the allowed R versions for the rostools courses.
#'
#' The allowed versions are those that are at maximum a year old from today,
#' sorted by the oldest first.
#'
#' @return A character vector of allowed R versions.
#' @export
#'
#' @examples
#' get_allowed_r_versions()
get_allowed_r_versions <- function() {
rversions::r_versions() |>
dplyr::filter(
date >= one_year_ago()
) |>
dplyr::pull(version)
}

#' Get a list of the allowed RStudio versions for the rostools courses.
#'
#' The versions are those that are at a maximum one year old from today,
#' sorted by the oldest first.
#'
#' @return A character vector of allowed RStudio versions.
#' @export
#'
#' @examples
#' get_allowed_rstudio_versions()
get_allowed_rstudio_versions <- function() {
versions <- gh::gh("/repos/:owner/:repo/tags", owner = "rstudio", repo = "rstudio") |>
purrr::map_chr("name") |>
stringr::str_subset("\\d{4}\\.\\d{2}")

tibble::tibble(
version = versions,
date = versions |>
stringr::str_extract("\\d{4}\\.\\d{2}") |>
stringr::str_c(".01") |>
lubridate::as_date()
) |>
dplyr::filter(
date >= one_year_ago()
) |>
dplyr::arrange(date) |>
dplyr::pull(version)
}

one_year_ago <- function() {
lubridate::today() - lubridate::years(1)
}
9 changes: 0 additions & 9 deletions data-raw/versions.R

This file was deleted.

18 changes: 18 additions & 0 deletions man/get_allowed_r_versions.Rd

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

18 changes: 18 additions & 0 deletions man/get_allowed_rstudio_versions.Rd

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

0 comments on commit a76b91a

Please sign in to comment.