Home > Software design >  List all datasets in current environment
List all datasets in current environment

Time:12-13

I am trying to get a list of all of the datasets that are available in my environment based on the packages loaded. Is there a simple way to do that?

CodePudding user response:

What about: data() ? Is this what you were looking for?

Data sets in package ‘datasets’:

AirPassengers                       Monthly Airline Passenger Numbers 1949-1960
BJsales                             Sales Data with Leading Indicator
BJsales.lead (BJsales)              Sales Data with Leading Indicator
BOD                                 Biochemical Oxygen Demand
CO2                                 Carbon Dioxide Uptake in Grass Plants
ChickWeight                         Weight versus age of chicks on different diets
DNase                               Elisa assay of DNase
EuStockMarkets                      Daily Closing Prices of Major European Stock Indices, 1991-1998
Formaldehyde                        Determination of Formaldehyde
HairEyeColor                        Hair and Eye Color of Statistics Students
[...]
Data sets in package ‘dplyr’:

band_instruments                    Band membership
band_instruments2                   Band membership
band_members                        Band membership
starwars                            Starwars characters
storms                              Storm tracks data

Data sets in package ‘forecast’:

gas                                 Australian monthly gas production
gold                                Daily morning gold prices
taylor                              Half-hourly electricity demand
wineind                             Australian total wine sales
woolyrnq                            Quarterly production of woollen yarn in Australia

Data sets in package ‘ggplot2’:

diamonds                            Prices of over 50,000 round cut diamonds
economics                           US economic time series
economics_long                      US economic time series
faithfuld                           2d density estimate of Old Faithful data
luv_colours                         'colors()' in Luv space
[... and many more ...]

CodePudding user response:

To get a character vector of all dataset names of attached packages (base packages included) we can use .packages() within data(), which by default lists (search() and searchpaths()) all the packages in the search path.

data(package = .packages())$result[, "Item"]
# or as a list
as.list(data(package = .packages())$result[, "Item"])

# if we load, say the tidyverse we expect a few more datasets
library(tidyverse)
length(x)
[1] 139
  • Related