NSRR data sets
nsrr_datasets(token = nsrr_token(), page = NULL)
nsrr_dataset(dataset = NULL, token = nsrr_token())
nsrr_dataset_files(dataset = NULL, path = NULL, token = nsrr_token())
token | Token for NSRR resources. Found at https://sleepdata.org/token |
---|---|
page | which page to grab. Increment over successive requests to retrieve all datasets. A request that return NULL or a number of datasets less than 18 indicates the last page. |
dataset | a dataset |
path | a folder or file path inside the dataset |
A data.frame
of the data sets and their endpoints
df = nsrr_datasets()
if (attributes(df)$status_code == 200) {
testthat::expect_is(df, "data.frame")
slugs = c("abc", "bestair", "chat", "ccshs", "cfs",
"heartbeat", "hchs", "homepap", "haassa", "learn")
testthat::expect_true(all(slugs %in% df$slug))
}
on_cran = !identical(Sys.getenv("NOT_CRAN"), "true")
on_ci <- nzchar(Sys.getenv("CI"))
local_run = grepl("musch", tolower(Sys.info()[["user"]]))
run_example = !on_cran || on_ci || local_run
if (run_example) {
df = nsrr_datasets(page = 1)
}
nsrr_dataset(dataset = "shhs", token = "")
#> $name
#> [1] "Sleep Heart Health Study"
#>
#> $slug
#> [1] "shhs"
#>
#> $created_at
#> [1] "2013-10-23T13:40:01.590-04:00"
#>
#> $updated_at
#> [1] "2020-04-04T20:10:22.971-04:00"
#>
#> attr(,"status_code")
#> [1] 200
dataset = "shhs"
token = NULL
df = nsrr_dataset_files(dataset)
ddf = nsrr_dataset_files(dataset, path = df$full_path[1])
dataset = "shhs"
token = NULL
df = nsrr_dataset_files(dataset)
nsrr_dataset_files("wecare")
#> Warning: Dataset not in set from NSRR
#> Warning: Content was NULL, returning the response for debuggin
#> Response [https://sleepdata.org/api/v1/datasets/wecare/files.json]
#> Date: 2021-05-17 15:16
#> Status: 204
#> Content-Type: <unknown>
#> <EMPTY BODY>
testthat::expect_error(nsrr_dataset_files(), "one data")
testthat::expect_error(nsrr_dataset_files(c("shhs", "chat")), "one data")