Skip to content

Commit

Permalink
adding some more error messages & validation
Browse files Browse the repository at this point in the history
ref #71
  • Loading branch information
wibeasley committed Jan 2, 2021
1 parent 453f231 commit 2cfa95b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ Authors@R: c(
"Jan", "Kanis", role = "ctb"
))
Imports:
checkmate,
httr,
jsonlite,
readr,
stats,
utils,
xml2
Suggests:
checkmate,
covr,
foreign,
haven,
Expand Down
18 changes: 11 additions & 7 deletions R/get_file_by_id.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,18 @@ get_file_by_id <-
...) {
format <- match.arg(format)

# single file ID
stopifnot(length(fileid) == 1)
if (length(fileid) != 1L)
stop("The fileid parameter must be single element.")

# must be a number OR doi string in the form of "doi:"
if (is.numeric(fileid))
use_persistentID <- FALSE
if (grepl(x = fileid, pattern = "^doi:"))
use_persistentID <- TRUE
use_persistent_id <- !is.numeric(fileid)
if (use_persistent_id) {
if (!grepl(x = fileid, pattern = "^doi:"))
stop("A 'persistent' fileid must be prefixed with 'doi:'. It was `", fileid, "`.")
} else {
if (!checkmate::check_integerish(fileid))
stop("A 'non-persistent' fileid must be a whole number. It was `", fileid, "`.")
}


# ping get_file_metadata to see if file is ingested
Expand Down Expand Up @@ -59,7 +63,7 @@ get_file_by_id <-
if (format == "original")
u_part <- "access/datafile/"

if (use_persistentID)
if (use_persistent_id)
u_part <- "access/datafile/:persistentId/?persistentId="

# If not bundle, request single file in non-bundle format ----
Expand Down

0 comments on commit 2cfa95b

Please sign in to comment.