Skip to content

Commit

Permalink
Fixing small bug when parsing flags. @pmarjora is (ctb,ths) now.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jun 28, 2019
1 parent ec746cb commit ac76c7e
Show file tree
Hide file tree
Showing 28 changed files with 55 additions and 50 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Title: A Lightweight Wrapper for Slurm
Version: 0.1-0
Authors@R: c(
person("George", "Vega Yon", email = "g.vegayon@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-3171-0844")),
person("Paul", "Marjoram", email = "pmarjora@usc.edu", role = c("aut"), comment = c(ORCID = "0000-0003-0824-7449")),
person("Paul", "Marjoram", email = "pmarjora@usc.edu", role = c("ctb", "ths"), comment = c(ORCID = "0000-0003-0824-7449")),
person("National Cancer Institute (NCI)", role = "fnd", comment = "Grant Number 5P01CA196569-02"),
person("Michael", "Schubert", role = "rev", comment = c(what = "JOSS reviewer", ORCID = "0000-0002-6862-5221")),
person("Michel", "Lang", role = "rev", comment = c(what = "JOSS reviewer", ORCID = "0000-0001-9754-0393"))
Expand Down
20 changes: 13 additions & 7 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ check_path <- function() {
#' @param ... Options to be parsed as bash flags.
#' @examples
#' cat(parse_flags(a=1, b=TRUE, hola=2, y="I have spaces", ms=2, `cpus-per-task`=4))
#' # -a=1 -b --hola=2 -y="I have spaces" --ms=2 --cpus-per-task=4
#' # -a 1 -b --hola=2 -y "I have spaces" --ms=2 --cpus-per-task=4
#' @export
#' @family Utility
parse_flags <- function(...) UseMethod("parse_flags")
Expand All @@ -46,23 +46,29 @@ parse_flags.list <- function(x, ...) {
if (!length(x))
return("")

single_char <- nchar(names(x)) == 1

option <- ifelse(
nchar(names(x)) > 1,
paste0("--", names(x)),
paste0("-", names(x))
single_char,
paste0("-", names(x)),
paste0("--", names(x))
)

vals <- character(length(option))
for (i in seq_along(x)) {

# Includes equal
equal_sign <- ifelse(single_char[i], " ", "=")

if (is.logical(x[[i]]) && !x[[i]])
option[i] <- ""
else if (!is.logical(x[[i]]) && !is.character(x[[i]]))
vals[i] <- paste0("=", x[[i]])
vals[i] <- paste0(equal_sign, x[[i]])
else if (is.character(x[[i]])) {
if (grepl("\\s+", x[[i]]))
vals[i] <- sprintf("=\"%s\"", x[[i]])
vals[i] <- sprintf("%s\"%s\"", equal_sign, x[[i]])
else
vals[i] <- sprintf("=%s", x[[i]])
vals[i] <- sprintf("%s%s", equal_sign, x[[i]])

}
}
Expand Down
2 changes: 1 addition & 1 deletion docs/404.html

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

2 changes: 1 addition & 1 deletion docs/CODE_OF_CONDUCT.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE-text.html

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

2 changes: 1 addition & 1 deletion docs/LICENSE.html

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

2 changes: 1 addition & 1 deletion docs/articles/getting-started.html

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

2 changes: 1 addition & 1 deletion docs/articles/index.html

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

4 changes: 2 additions & 2 deletions docs/authors.html

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

29 changes: 14 additions & 15 deletions docs/index.html

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

2 changes: 1 addition & 1 deletion docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/reference/Slurm_EvalQ.html

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

2 changes: 1 addition & 1 deletion docs/reference/Slurm_clean.html

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

2 changes: 1 addition & 1 deletion docs/reference/Slurm_collect.html

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

2 changes: 1 addition & 1 deletion docs/reference/Slurm_env.html

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

2 changes: 1 addition & 1 deletion docs/reference/Slurm_lapply.html

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

2 changes: 1 addition & 1 deletion docs/reference/WhoAmI.html

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

2 changes: 1 addition & 1 deletion docs/reference/index.html

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

2 changes: 1 addition & 1 deletion docs/reference/new_rscript.html

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

2 changes: 1 addition & 1 deletion docs/reference/opts_sluRm.html

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

Loading

0 comments on commit ac76c7e

Please sign in to comment.