R/promptDatasets.R

Defines functions promptDatasets

Documented in promptDatasets

#' Prompt for dataset in the console
#' @name promptDatasets
#' @importFrom utils data menu
#' @param package a character vector with the names of packages to search through, or NULL in which "all" packages (as defined by argument all) are searched.
#' @param lib.loc a character vector of directory names of R libraries, or NULL. The default value of NULL corresponds to all libraries currently known.
#' @param all logical; if TRUE search all available packages in the library trees specified by lib.loc, and if FALSE, search only attached packages.
#' @param drop.defaults logical; if TRUE, do not include the datasets from the datasets package.
#' @export

promptDatasets <- function(package = NULL, lib.loc = NULL, all=TRUE, drop.defaults=FALSE) {

  # return dataset info
  dtsts <- datasets(package, lib.loc, all, drop.defaults)

  # prompt which dataset to load
  choice <- utils::menu(dtsts[,3])

  # find corresponding package
  pkgs <- dtsts[choice,1]

  # find corresponding dataset
  dtsts <- dtsts[choice,2]

  return( utils::data(list=dtsts, package=pkgs) )

}
bquast/datasets.load documentation built on Nov. 16, 2023, 3:29 a.m.