knitr::opts_chunk$set( collapse = TRUE, comment = "#>" )
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()
Here is how you can access the NSRR datasets list:
library(nsrr) df = nsrr_datasets() DT::datatable(df)
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)
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")
To list all the files, recursively, you would run:
nsrr_all_dataset_files("shhs")
but it may take some time.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.