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:
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:
Here is how you can access the NSRR datasets list:
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)
#> dataset full_path folder file_name
#> 1 shhs datasets/archive datasets/ archive
#> 2 shhs datasets/hrv-analysis datasets/ hrv-analysis
#> 3 shhs datasets/CHANGELOG.md datasets/ CHANGELOG.md
#> 4 shhs datasets/KNOWNISSUES.md datasets/ KNOWNISSUES.md
#> 5 shhs datasets/shhs1-dataset-0.15.0.csv datasets/ shhs1-dataset-0.15.0.csv
#> 6 shhs datasets/shhs2-dataset-0.15.0.csv datasets/ shhs2-dataset-0.15.0.csv
#> is_file file_size file_checksum_md5 archived
#> 1 FALSE 0 <NA> FALSE
#> 2 FALSE 0 <NA> FALSE
#> 3 TRUE 11010 69bb54a32cdfc7bdddc13276b7c858c1 FALSE
#> 4 TRUE 11421 8598129123baa60e16977dc24aa780af FALSE
#> 5 TRUE 24322962 3f26d37ec97e2bc88776850a31715398 FALSE
#> 6 TRUE 11897377 21807d854010f036fd0d4f006eeed49d FALSE
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
#> [1] "https://sleepdata.org/datasets/shhs/files/m/nsrr-r-v0-2-0/datasets/CHANGELOG.md"
dl = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md", token = "")
dl$outfile
#> [1] "/var/folders/1s/wrtqcpxn685_zk570bnx9_rr0000gr/T//Rtmp6DjjQk/file124e55e9a845e.md"
cat(head(readLines(dl$outfile)), sep = "\n")
#> ## 0.15.0 (November 18, 2019)
#>
#> - Remove EEG spectral summary variables
#> - Add notes to height and weight varibles about top and bottom coding
#> - The CSV datasets generated from a SAS export are located here:
#> - `\\rfawin\bwh-sleepepi-shhs\nsrr-prep\_releases\0.15.0\`