Skip to content

Commit

Permalink
should be 100%
Browse files Browse the repository at this point in the history
  • Loading branch information
muschellij2 committed Mar 3, 2019
1 parent 19c80d6 commit 067f99d
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 10 deletions.
10 changes: 10 additions & 0 deletions R/biostat_data.R
Expand Up @@ -9,7 +9,17 @@
#' @examples
#' biostat_data("bmi_age.txt")
#' biostat_data("FLAIR.nii.gz")
#' ff = system.file("extdata", "shhs1.txt", package = "biostatmethods")
#' if (file.exists(ff)) {
#' file.remove(ff)
#' }
#' testthat::expect_error(biostat_data("shhs1.txt"))
#' token = nsrr::nsrr_token()
#' if (!is.null(token)) {
#' if (biostat_download_shhs()) {
#' biostat_data("shhs1.txt")
#' }
#' }
biostat_data = function(...) {
args = list(...)
args = unlist(args)
Expand Down
20 changes: 13 additions & 7 deletions R/biostat_download_shhs.R
Expand Up @@ -2,31 +2,37 @@
#'
#' @param token Token for 'NSRR' data resource, to pass to
#' @param out_dir Directory to download the file
#' @param overwrite Should the file be overwritten if exists already?
#'
#' @return A logical if the data was downloaded
#' @importFrom nsrr nsrr_download_file nsrr_token
#' @export
#'
#' @examples
#' token = nsrr::nsrr_token()
#' res = biostat_download_shhs(token = "", overwrite = TRUE)
#' testthat::expect_false(res)
#' if (!is.null(token)) {
#' res = biostat_download_shhs()
#' testthat::expect_true(res)
#' }
#' res = biostat_download_shhs(token = "")
#' testthat::expect_false(res)
biostat_download_shhs = function(
token = nsrr::nsrr_token(),
out_dir = system.file(package = "biostatmethods")) {
out_dir = system.file("extdata", package = "biostatmethods"),
overwrite = FALSE) {
args = list(dataset = "shhs",
path = "biostatistics-with-r/shhs1.txt")
args$token = token
res = do.call(nsrr::nsrr_download_file, args = args)
outfile = file.path(out_dir, "shhs1.txt")
if (res$success) {
file.copy(res$outfile, outfile, overwrite = TRUE)
if (!file.exists(outfile) | overwrite) {
res = do.call(nsrr::nsrr_download_file, args = args)
if (res$success) {
file.copy(res$outfile, outfile, overwrite = TRUE)
}
success = res$success
} else {
success = file.exists(outfile)
}
success = res$success
attr(success, "outfile") = outfile
return(success)
}
10 changes: 10 additions & 0 deletions man/biostat_data.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/biostat_download_shhs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 067f99d

Please sign in to comment.