## ----include = FALSE----------------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  eval = FALSE,
  comment = "#>"
)

## -----------------------------------------------------------------------------
library(roam)

bee <- new_roam("roam", "bee", \(version) "buzzz")
class(bee)

## -----------------------------------------------------------------------------
options(roam.autodownload = TRUE)
roam_activate(bee)
bee

## -----------------------------------------------------------------------------
# roam_install(bee)
# roam_delete(bee)

## -----------------------------------------------------------------------------
# new_roam(package, name, obtainer, ...)

## -----------------------------------------------------------------------------
# bee <- new_roam(
#   "roam.demo",
#   "bee",
#   function(version) {
#     read.csv(
#       "https://raw.githubusercontent.com/finyang/roam/master/demo/bee_colonies.csv"
#     )
#   }
# )

## -----------------------------------------------------------------------------
# #' @import roam
# .onLoad <- function(libname, pkgname) {
#   roam_activate_all("roam.demo")
# }

## -----------------------------------------------------------------------------
# roam_activate(bee)

## -----------------------------------------------------------------------------
# #' beeeeeeee
# #'
# #' @format buzzzzzzzz
# #' @export

## -----------------------------------------------------------------------------
# # tidytuesday2026Jan is another example data in `roam.demo`
# roam_install(tidytuesday2026Jan, version = "latest")
# # roam_update() is a wrapper of roam_install()
# # with the version set to "latest"
# roam_update(tidytuesday2026Jan)

## -----------------------------------------------------------------------------
# tidytuesday2026Jan <- new_roam(
#   "roam.demo",
#   "tidytuesday2026Jan",
#   function(version) {
#     if ((!is.character(version)) || length(version) > 1) {
#       stop("version must be a length character")
#     }
#     if (
#       !is.na(version) && (!version %in% c("latest", "2026-01-20", "2026-01-13"))
#     ) {
#       stop("invalid version number")
#     }
#     if (is.na(version) || version %in% c("latest", "2026-01-20")) {
#       roam_set_version("2026-01-20")
#       read.csv(
#         "https://raw.githubusercontent.com/rfordatascience/tidytuesday/refs/heads/main/data/2026/2026-01-20/apod.csv"
#       )
#     } else {
#       roam_set_version("2026-01-13")
#       read.csv(
#         "https://raw.githubusercontent.com/rfordatascience/tidytuesday/refs/heads/main/data/2026/2026-01-13/africa.csv"
#       )
#     }
#   }
# )

## -----------------------------------------------------------------------------
# if ((!is.character(version)) || length(version) > 1) {
#   stop("version must be a length character")
# }
# if (
#   !is.na(version) && (!version %in% c("latest", "2026-01-20", "2026-01-13"))
# ) {
#   stop("invalid version number")
# }

## -----------------------------------------------------------------------------
# if (is.na(version) || version %in% c("latest", "2026-01-20")) {
#   roam_set_version("2026-01-20")
#   read.csv(
#     "https://raw.githubusercontent.com/rfordatascience/tidytuesday/refs/heads/main/data/2026/2026-01-20/apod.csv"
#   )
# } else {
#   roam_set_version("2026-01-13")
#   read.csv(
#     "https://raw.githubusercontent.com/rfordatascience/tidytuesday/refs/heads/main/data/2026/2026-01-13/africa.csv"
#   )
# }

## -----------------------------------------------------------------------------
# roam_set_version("2026-01-13")

## -----------------------------------------------------------------------------
# roam_version("roam.demo", "tidytuesday2026Jan")

