R/getDatasetInfo.R

Defines functions getDatasetInfo

Documented in getDatasetInfo

#' Get information on installed datasets.
#' @name getDatasetInfo
#' @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

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

  if (is.null(package)) {
    package <- .packages(all.available = all, lib.loc)

    # drop these to avoid warnings
    package <- setdiff(package, c("base", "stats"))

    # remove data available by default if specified
    if (drop.defaults == TRUE) {
      package <- setdiff(package, "datasets")
    }

    # this doesn't do anything here
    paths <- find.package(package, lib.loc, quiet = TRUE)
  }
  else { # this doesn't work yet
    paths <- find.package(package, lib.loc)
  }

  # extract datasets info
  package <- as.data.frame( data(package = package)$result, stringsAsFactors=FALSE )

  class(package) <- c('datasets', 'data.frame')

  return(package)

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