NSRR Download file

nsrr_download_url(dataset, path, token = nsrr_token())

nsrr_download_file(dataset, path, token = nsrr_token(), check_md5 = TRUE)

Arguments

dataset

a dataset "slug", one from nsrr_datasets

path

full path to the file.

token

Token for NSRR resources. Found at https://sleepdata.org/token

check_md5

check if MD5 checksum agrees when downloaded

Value

A data.frame of the data sets and their endpoints

Examples

if (requireNamespace("xml2", quietly = TRUE) &
requireNamespace("rvest", quietly = TRUE)) {
doc = xml2::read_html("https://sleepdata.org/datasets/shhs/files/datasets")
tab = rvest::html_table(doc)[[1]]
path = tab$X2
path = path[ grepl("shhs-data-dictionary-.*-domains", path)]
path = path[1]
path = paste0("datasets/", path)
} else {
path = "datasets/shhs-data-dictionary-0.14.0-domains.csv"
}
dataset = "shhs"
nsrr_download_url(dataset, path, token = "")
#> [1] "https://sleepdata.org/datasets/shhs/files/m/nsrr-r-v0-1-5/datasets/shhs-data-dictionary-0.15.0-domains.csv"
if (nsrr_have_token()) {
res = nsrr_download_file(dataset, path)
testthat::expect_true(res$success)
path = "biostatistics-with-r/shhs1.txt"
res = nsrr_download_file(dataset, path)
}
url = nsrr_download_url("shhs", path = "datasets/CHANGELOG.md",
token = NULL)
res = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md",
token = NULL)
testthat::expect_true(res$correct_md5)
res = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md",
token = NULL, check_md5 = FALSE)
testthat::expect_null(res$correct_md5)