Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/muschellij2/nsrr
Interface to National Sleep Research Resource
https://github.com/muschellij2/nsrr
Last synced: 2 months ago
JSON representation
Interface to National Sleep Research Resource
- Host: GitHub
- URL: https://github.com/muschellij2/nsrr
- Owner: muschellij2
- License: gpl-3.0
- Created: 2019-01-30T17:07:33.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-13T00:10:19.000Z (about 3 years ago)
- Last Synced: 2023-08-13T09:10:12.365Z (over 1 year ago)
- Language: R
- Size: 3.17 MB
- Stars: 4
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
- License: LICENSE.md
Awesome Lists containing this project
README
---
output: github_document
---```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# nsrr[![Travis build status](https://travis-ci.com/muschellij2/nsrr.svg?branch=master)](https://travis-ci.com/muschellij2/nsrr)
[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/muschellij2/nsrr?branch=master&svg=true)](https://ci.appveyor.com/project/muschellij2/nsrr)
[![Codecov test coverage](https://codecov.io/gh/muschellij2/nsrr/branch/master/graph/badge.svg)](https://codecov.io/gh/muschellij2/nsrr?branch=master)The goal of nsrr is to allow users to access data from the National Sleep Research Resource ('NSRR') (https://sleepdata.org/) through an `R` interface.
Why `R`? Many packages in `R` can read and process accelerometry, such as the [`GGIR`](https://cran.r-project.org/package=GGIR), [`ActivityIndex`](https://cran.r-project.org/package=ActivityIndex), and [`accelerometry`](https://cran.r-project.org/package=accelerometry); other packages such as [`edfReader`](https://cran.r-project.org/package=edfReader) can read in EDF data for polysomnography data. Also, the [`xml2`](https://cran.r-project.org/package=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.
## Installation
You can install the released version of nsrr from [CRAN](https://CRAN.R-project.org) with:
``` r
install.packages("nsrr")
```## 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:
```r
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:
```{r}
library(nsrr)
nsrr_auth()
```## Examples
### NSRR data sets
Here is how you can access the NSRR datasets list:
```{r example}
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:
```{r ls}
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.
```{r dl}
url = nsrr_download_url("shhs", path = "datasets/CHANGELOG.md")
# print URL
dl = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md")
dl$outfile
cat(head(readLines(dl$outfile)), sep = "\n")
```### Listing All NSRR data set files
To list all the files, recursively, you would run:
```{r, eval = FALSE}
nsrr_all_dataset_files("shhs")
```
but it may take some time.### EDF files
The [`edfReader`](https://cran.r-project.org/package=edfReader) can read in EDF fields for polysomnography data. **Work in Progress - need access to EDF data**.
```{r, eval = FALSE}
files = nsrr_dataset_files("shhs", path= "polysomnography/edfs/shhs1")
dl = nsrr_download_file("shhs", path = "polysomnography/edfs/shhs1/shhs1-200001.edf")
```