The goal of nsrr is to allow users to access data from the National Sleep Research Resource (’NSRR’) ( through an R interface.

Why R? Many packages in R can read and process accelerometry, such as the GGIR, ActivityIndex, and accelerometry; other packages such as edfReader can read in EDF data for polysomnography data. Also, the xml2 package can easily read in XML annotations into R. We believe the interplay with these packages, amongst others, allow for a flexible framework to download, process, and visualize data. The nsrr package is simply the entry point into navigating the files available and downloading the data.


You can install the released version of nsrr from CRAN with:


To retrieve your NSRR token, go to, 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:


NSRR data sets

Here is how you can access the NSRR datasets list:

Listing All NSRR data set files

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

but it may take some time.

EDF files

The edfReader can read in EDF fields for polysomnography data. Work in Progress - need access to EDF data.

files = nsrr_dataset_files("shhs", path= "polysomnography/edfs/shhs1")
dl = nsrr_download_file("shhs", path = "polysomnography/edfs/shhs1/shhs1-200001.edf")