Skip to content

Commit

Permalink
Use seq_along instead of colon
Browse files Browse the repository at this point in the history
  • Loading branch information
caiohamamura committed Oct 25, 2023
1 parent ea5a8b0 commit 12f92c7
Showing 1 changed file with 31 additions and 31 deletions.
62 changes: 31 additions & 31 deletions R/argParse.R
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
stopifnotMessage = function(...) {
ok = TRUE
errors = list()
listargs = list(...)
for (i in 1:length(listargs)) {
if (listargs[i] == FALSE) {
errors[[""]] = names(listargs)[i]
ok = FALSE
}
}
if (ok == FALSE) {
stop(paste0("\n\nWhen validating the arguments:\n ", paste(errors, collapse="\n ")))
}
}

checkLogical = function(x) {
return (is.null(x) || (length(x) == 1 && is.logical(x)))
}

checkInteger = function(x) {
x_int = as.integer(x)
return (is.null(x) || (length(x_int) == 1 && is.integer(x_int) && !is.na(x_int)))
}

checkParentDir = function(x, optional=FALSE) {
if (optional && is.null(x)) {
return (TRUE)
}
dirName = fs::path_dir(x)
return (fs::dir_exists(dirName)[[1]])
}
stopifnotMessage = function(...) {
ok = TRUE
errors = list()
listargs = list(...)
for (i in seq_along(listargs)) {
if (listargs[i] == FALSE) {
errors[[""]] = names(listargs)[i]
ok = FALSE
}
}
if (ok == FALSE) {
stop(paste0("\n\nWhen validating the arguments:\n ", paste(errors, collapse="\n ")))
}
}

checkLogical = function(x) {
return (is.null(x) || (length(x) == 1 && is.logical(x)))
}

checkInteger = function(x) {
x_int = as.integer(x)
return (is.null(x) || (length(x_int) == 1 && is.integer(x_int) && !is.na(x_int)))
}

checkParentDir = function(x, optional=FALSE) {
if (optional && is.null(x)) {
return (TRUE)
}
dirName = fs::path_dir(x)
return (fs::dir_exists(dirName)[[1]])
}

0 comments on commit 12f92c7

Please sign in to comment.