nsrr_download_url: NSRR Download file

Description Usage Arguments Value Examples

View source: R/nsrr_download.R

Description

NSRR Download file

Usage

1
2
3
4
5
6
7
8
9
nsrr_download_url(dataset, path, token = nsrr_token())

nsrr_download_file(
  dataset,
  path,
  token = nsrr_token(),
  check_md5 = TRUE,
  check_filesize = TRUE
)

Arguments

dataset

a dataset "slug", one from nsrr_datasets

path

full path to the file.

token

Token for NSRR resources. Found at https://sleepdata.org/token

check_md5

check if MD5 checksum agrees when downloaded

check_filesize

check the file size versus the 'API'

Value

A data.frame of the data sets and their endpoints

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
if (requireNamespace("xml2", quietly = TRUE) &
    requireNamespace("rvest", quietly = TRUE)) {
  res = httr::with_config(
    config = httr::config(ssl_verifypeer = FALSE),
    httr::GET("https://sleepdata.org/datasets/shhs/files/datasets")
  )
  if (httr::status_code(res) < 400) {
    doc = httr::content(res)
    tab = rvest::html_table(doc)[[1]]
    path = tab$X2
    path = path[ grepl("shhs-data-dictionary-.*-domains", path)]
    path = path[1]
    path = paste0("datasets/", path)
  } else {
    path = "datasets/shhs-data-dictionary-0.16.0-domains.csv"
  }
} else {
  path = "datasets/shhs-data-dictionary-0.16.0-domains.csv"
}
dataset = "shhs"
nsrr_download_url(dataset, path, token = "")
if (nsrr_have_token()) {
  res = nsrr_download_file(dataset, path, check_md5 = FALSE,
                           check_filesize = FALSE)
  testthat::expect_true(res$success)
}
url = nsrr_download_url("shhs", path = "datasets/CHANGELOG.md",
                        token = NULL)
res = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md",
                         token = NULL)
testthat::expect_true(res$correct_md5)

  res = nsrr_download_file("shhs", path = "datasets/CHANGELOG.md",
                           token = NULL, check_md5 = FALSE)
  testthat::expect_null(res$correct_md5)
  if (nsrr_have_token()) {
    path = "biostatistics-with-r/shhs1.txt"
    res = nsrr_download_file(dataset, path)
  }

muschellij2/nsrr documentation built on Oct. 17, 2021, 9:20 p.m.