Downloading data from NSRR

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)

Token

To retrieve your NSRR token, go to https://sleepdata.org/dashboard, and sign in. This token will allow you access to any data sets you have requested access to. If you do not have access, then it will allow you to download files that are publicly available.

Set the token by adding this to your ~/.Renviron file:

NSRR_TOKEN="YOUR TOKEN GOES HERE"

The token is accessible via token = Sys.getenv("NSRR_TOKEN"). Each nsrr function also has the argument token to pass through if you do not wish to set it.

To determine if you are authenticated, you can use:

library(nsrr)
nsrr_auth()

Examples

NSRR data sets

Here is how you can access the NSRR datasets list:

library(nsrr)
df = nsrr_datasets()
DT::datatable(df)

NSRR data set files

Here we first get a list of the files in the datasets sub-directory from the shhs data set:

df = nsrr_dataset_files("shhs", path = "datasets")
head(df)

Downloading NSRR data set files

We can then download the CHANGELOG.md file as it's publicly accessible.

url = nsrr_download_url("shhs", path = "datasets/CHANGELOG.md", token = "")
url # print URL
dl = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md", token = "")
dl$outfile
cat(head(readLines(dl$outfile)), sep = "\n")

Listing All NSRR data set files

To list all the files, recursively, you would run:

nsrr_all_dataset_files("shhs")

but it may take some time.



Try the nsrr package in your browser

Any scripts or data that you put into this service are public.

nsrr documentation built on July 8, 2020, 5:52 p.m.