Skip to contents

With file = NULL, downloads the metadata Kaggle generates for a public dataset (https://www.kaggle.com/datasets/<owner>/<slug>/croissant/download), the document the dataset page exports as Croissant, and reads it with read_croissant(). Kaggle serves this metadata for public datasets. The metadata describes the dataset's current version. Its record sets read through read_record_set(), which downloads the version's zip archive from the Kaggle API, checks its MD5, and extracts the files the record set reads.

Usage

read_croissant_kaggle(dataset, file = NULL, token = NULL, verbosity = 1L)

Arguments

dataset

Character: Dataset, as <owner>/<slug> or as its URL, https://www.kaggle.com/datasets/<owner>/<slug>.

file

Optional Character: Path of a Croissant file in the dataset, such as "croissant.json". If NULL, the metadata Kaggle generates is read.

token

Optional Character: Kaggle API token, used with file. NULL reads KAGGLE_API_TOKEN, then ~/.kaggle/access_token.

verbosity

Integer: Verbosity level; 1L reports the dataset before reading, and the dataset name and counts of record sets, enumerations, and files after.

Value

Croissant object.

Details

With file, reads a Croissant file stored in the dataset, from the Kaggle API (https://www.kaggle.com/api/v1/datasets/download/<owner>/<slug>/<file>). Its relative contentUrls resolve to the dataset's files on the Kaggle API, so read_record_set() downloads each file a record set reads.

Requests to the Kaggle API carry the Kaggle API token when there is one, which a private dataset requires. The token is resolved as the Kaggle command-line tool and 'kagglehub' resolve it: token; the KAGGLE_API_TOKEN environment variable, holding the token or the path of a file that holds it; and the file ~/.kaggle/access_token. A token is created at https://www.kaggle.com/settings/api.

Author

EDG

Examples

if (FALSE) { # interactive()
# The metadata Kaggle generates
x <- read_croissant_kaggle("heptapod/titanic")
x
cache_dir <- tempfile()
head(read_record_set(
  x,
  "train_and_test2.csv",
  n_max = 5L,
  cache_dir = cache_dir
))
# A Croissant file stored in the dataset
y <- read_croissant_kaggle("rtemisorg/rtemis-demo", file = "croissant.json")
read_record_set(y, "classification", cache_dir = cache_dir)
unlink(cache_dir, recursive = TRUE)
}