From 721b5ed0562d477e02c3320896864f85cd41036a Mon Sep 17 00:00:00 2001 From: "Zhang, Jitao David {GTAD~BASEL}" Date: Thu, 12 Feb 2026 09:17:20 +0000 Subject: [PATCH 1/9] Add reference URL to DESCRIPTION and quote 'BIOS' Add Zhang (2025) to Description field per CRAN policy. Quote 'BIOS' as non-standard term. Update .Rbuildignore for CRAN-FEEDBACK.md. Co-authored-by: Ona --- .Rbuildignore | 1 + DESCRIPTION | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/.Rbuildignore b/.Rbuildignore index 054e0b7..80e1dc9 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -18,3 +18,4 @@ ^bin$ ^CRAN-SUBMISSION$ ^CRAN-PREPARATION\.md$ +^CRAN-FEEDBACK\.md$ \ No newline at end of file diff --git a/DESCRIPTION b/DESCRIPTION index 8ef1d5c..a24edcb 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -12,7 +12,8 @@ Authors@R: person("F.Hoffmann-La Roche AG", role="cph")) Description: Provides functions to handle command-line arguments for R scripting. It enables building stand-alone R programs that accept and - parse command-line options in BIOS style. + parse command-line options in 'BIOS' style. + Zhang (2025) . Depends: R (>= 3.4.0), ribiosUtils From 2cb2fa30a69a1a55a8f975206009e5087179fc7c Mon Sep 17 00:00:00 2001 From: "Zhang, Jitao David {GTAD~BASEL}" Date: Thu, 12 Feb 2026 09:17:43 +0000 Subject: [PATCH 2/9] Address CRAN review feedback - Add \value tags to makeFactor, parseFactor, parseFiles, parseNumVec, scriptSkeleton .Rd files - Replace all \dontrun{} with \donttest{} in examples - Add on.exit(options(old)) to scriptInit() to restore options - Fix bogus aliases in scriptInit.Rd - Use tempdir() in scriptSkeleton example to avoid writing to user filespace Co-authored-by: Ona --- R/argparse.R | 6 +++--- R/parseFuncs.R | 6 +++++- R/scriptInit.R | 12 +++++++----- R/scriptName.R | 4 ++-- R/scriptSkeleton.R | 4 +++- man/argGet.Rd | 2 +- man/argGetPos.Rd | 2 +- man/argParse.Rd | 2 +- man/makeFactor.Rd | 3 +++ man/parseFactor.Rd | 5 ++++- man/parseFiles.Rd | 3 +++ man/parseNumVec.Rd | 3 +++ man/scriptInit.Rd | 27 ++++----------------------- man/scriptName.Rd | 2 +- man/scriptPath.Rd | 2 +- man/scriptSkeleton.Rd | 6 +++++- 16 files changed, 47 insertions(+), 42 deletions(-) diff --git a/R/argparse.R b/R/argparse.R index 1a7e8ac..1e5d77f 100644 --- a/R/argparse.R +++ b/R/argparse.R @@ -37,7 +37,7 @@ #' @useDynLib ribiosArg, .registration=TRUE, .fixes="C_" #' #' @examples -#' \dontrun{ +#' \donttest{ #' argParse("verbose threshold,2", "infile outfile", #' usage="prog [-infile ]infile [-outfile ]outfile [-verbose] [-threshold MIN MAX]") #' argIsInit() @@ -147,7 +147,7 @@ argPresent <- function(opt) { #' @seealso \code{\link{argParse}}, \code{\link{argGet}}, and \code{\link{argPresent}} #' #' @examples -#' \dontrun{argGetPos("thresholds", ind=2)} +#' \donttest{argGetPos("thresholds", ind=2)} #' #' @export argGetPos <- function(opt, ind=1L, default=NULL, choices=NULL) { @@ -182,7 +182,7 @@ argGetPos <- function(opt, ind=1L, default=NULL, choices=NULL) { #' @seealso \code{\link{argParse}}, \code{\link{argGetPos}}, and \code{\link{argPresent}} #' #' @examples -#' \dontrun{argGet("infile")} +#' \donttest{argGet("infile")} #' #' @export argGet <- function(opt, default=NULL, choices=NULL) { diff --git a/R/parseFuncs.R b/R/parseFuncs.R index 1d57dc6..29a732b 100644 --- a/R/parseFuncs.R +++ b/R/parseFuncs.R @@ -13,6 +13,7 @@ #' @param failVal If the parsing failed (for example length not correct, or non-numeric values were provided, this value will be returned #' @param sep Separator in the character string, default "," #' +#' @return A numeric vector of the parsed values, or \code{failVal} if parsing fails. #' @seealso \code{\link{argGet}} #' #' @export @@ -127,6 +128,7 @@ parsePairs <- function(str, collapse=",", sep="=", #' @param make.names Should names be converted to adhere to the rule of variable names in R #' @param verbose Logical vector #' +#' @return A factor with the specified levels. #' @export #' @examples #' makeFactor(c("A", "B", "C", "C", "A"), levels=LETTERS[3:1]) @@ -178,6 +180,7 @@ makeFactor <- function(groups, levels=NULL, make.names=TRUE, verbose=FALSE) { #' @param make.names Logical, should names be converted to adhere to the rule of variable names in R #' @param collapse Character used in \code{relevels} to collapse different levels #' +#' @return A factor parsed from the input string with the specified levels. #' @export #' @examples #' parseFactor("A,B,C,B,A", rlevels="A,B,C") @@ -194,7 +197,7 @@ makeFactor <- function(groups, levels=NULL, make.names=TRUE, verbose=FALSE) { #' groups <- factor(c("B", "C", "A", "D"), levels=c("D","C","A","B")) #' makeFactor(groups) #' -#' \dontrun{ +#' \donttest{ #' groups <- c("ATest", "Control", "Control", "ATest") #' levels <- c("Control", "ATest", "Unknown") #' makeFactor(groups, levels) @@ -233,6 +236,7 @@ isDir <- function(str) file.info(str)$isdir #' @param recursive In cse of directory or compressed files, whether files should be found recursively #' @param ignore.case In case of directory or compressed files, whether case should be ignored #' +#' @return A character vector of file paths. #' @importFrom ribiosUtils extname #' @importFrom utils untar unzip #' @export diff --git a/R/scriptInit.R b/R/scriptInit.R index 73d72fd..e9332a7 100644 --- a/R/scriptInit.R +++ b/R/scriptInit.R @@ -1,17 +1,19 @@ #' Prepare the environment for a script -#' @aliases initScript -#' +#' #' This function is called at the beginning of an Rscript, in order to #' prepare the R environment to run in a script setting. #' -#' @return Only side effect is used -#' +#' @return No return value, called for side effects. +#' +#' @aliases initScript #' @export #' @examples -#' \dontrun{ +#' \donttest{ #' scriptInit() #' } scriptInit <- function() { + old <- options() + on.exit(options(old)) if(interactive()) { setDebug() } else { diff --git a/R/scriptName.R b/R/scriptName.R index 97f340f..a9e0342 100644 --- a/R/scriptName.R +++ b/R/scriptName.R @@ -15,7 +15,7 @@ #' #' @export #' @examples -#' \dontrun{scriptName()} +#' \donttest{scriptName()} #' scriptName <- function() { filename <- grep("--file=", commandArgs(), value=TRUE) @@ -49,7 +49,7 @@ scriptName <- function() { #' #' @export #' @examples -#' \dontrun{scriptPath()} +#' \donttest{scriptPath()} #' scriptPath <- function() { sname <- scriptName() diff --git a/R/scriptSkeleton.R b/R/scriptSkeleton.R index 99d9ab7..3222762 100644 --- a/R/scriptSkeleton.R +++ b/R/scriptSkeleton.R @@ -2,9 +2,11 @@ #' #' @param file Output file. By default the function writes to standard output. #' +#' @return Invisibly returns the character vector of skeleton lines. +#' Called for its side effect of writing to \code{file}. #' @export #' @examples -#' scriptSkeleton() +#' scriptSkeleton(file = file.path(tempdir(), "myscript.R")) scriptSkeleton <- function(file=stdout()) { sentences <- c("#!/usr/bin/env Rscript", diff --git a/man/argGet.Rd b/man/argGet.Rd index 2611e54..87ff877 100644 --- a/man/argGet.Rd +++ b/man/argGet.Rd @@ -23,7 +23,7 @@ Get the value of an named argument The parsing is performed at C-level. It is an abbreiviation of argGetPos(opt, ind=1, default=NULL, choices=NULL) } \examples{ -\dontrun{argGet("infile")} +\donttest{argGet("infile")} } \seealso{ diff --git a/man/argGetPos.Rd b/man/argGetPos.Rd index 1522e49..be323bb 100644 --- a/man/argGetPos.Rd +++ b/man/argGetPos.Rd @@ -25,7 +25,7 @@ Get the value of an named argument with the given position The parsing is performed at C-level. If the argument accepts only one value, users can also call argGet(opt, default=NULL, choices=NULL) } \examples{ -\dontrun{argGetPos("thresholds", ind=2)} +\donttest{argGetPos("thresholds", ind=2)} } \seealso{ diff --git a/man/argParse.Rd b/man/argParse.Rd index 78b3d0c..ec97d77 100644 --- a/man/argParse.Rd +++ b/man/argParse.Rd @@ -53,7 +53,7 @@ Test whether the given option is present in the command line or not \code{default} value will be returned. } \examples{ -\dontrun{ +\donttest{ argParse("verbose threshold,2", "infile outfile", usage="prog [-infile ]infile [-outfile ]outfile [-verbose] [-threshold MIN MAX]") argIsInit() diff --git a/man/makeFactor.Rd b/man/makeFactor.Rd index 5154fc4..4e246e1 100644 --- a/man/makeFactor.Rd +++ b/man/makeFactor.Rd @@ -15,6 +15,9 @@ makeFactor(groups, levels = NULL, make.names = TRUE, verbose = FALSE) \item{verbose}{Logical vector} } +\value{ +A factor with the specified levels. +} \description{ Make a factor } diff --git a/man/parseFactor.Rd b/man/parseFactor.Rd index f2c9a91..5beea99 100644 --- a/man/parseFactor.Rd +++ b/man/parseFactor.Rd @@ -15,6 +15,9 @@ parseFactor(str, rlevels = NULL, make.names = TRUE, collapse = ",") \item{collapse}{Character used in \code{relevels} to collapse different levels} } +\value{ +A factor parsed from the input string with the specified levels. +} \description{ Parse a character string into factor } @@ -33,7 +36,7 @@ makeFactor(groups, levels) groups <- factor(c("B", "C", "A", "D"), levels=c("D","C","A","B")) makeFactor(groups) -\dontrun{ +\donttest{ groups <- c("ATest", "Control", "Control", "ATest") levels <- c("Control", "ATest", "Unknown") makeFactor(groups, levels) diff --git a/man/parseFiles.Rd b/man/parseFiles.Rd index 088c4fd..85a32c5 100644 --- a/man/parseFiles.Rd +++ b/man/parseFiles.Rd @@ -23,6 +23,9 @@ parseFiles( \item{ignore.case}{In case of directory or compressed files, whether case should be ignored} } +\value{ +A character vector of file paths. +} \description{ Parse files from command line option, which can be (1) a string vector of files, (2) a file listing input files (e.g. pointer file), (3) a directory, or (4) a zip/tar/gz file (determined by suffix). In the later two cases, file patterns can be specified. } diff --git a/man/parseNumVec.Rd b/man/parseNumVec.Rd index c5db577..129ec9a 100644 --- a/man/parseNumVec.Rd +++ b/man/parseNumVec.Rd @@ -15,6 +15,9 @@ parseNumVec(str, expLen = 2, failVal = c(5, 5), sep = ",") \item{sep}{Separator in the character string, default ","} } +\value{ +A numeric vector of the parsed values, or \code{failVal} if parsing fails. +} \description{ Numeric vectors can be given as arguments in two ways: (1) separated by blanks or (2) separated by other common separators, such as comma diff --git a/man/scriptInit.Rd b/man/scriptInit.Rd index 83cc315..7ff44cb 100644 --- a/man/scriptInit.Rd +++ b/man/scriptInit.Rd @@ -3,38 +3,19 @@ \name{scriptInit} \alias{scriptInit} \alias{initScript} -\alias{This} -\alias{function} -\alias{is} -\alias{called} -\alias{at} -\alias{the} -\alias{beginning} -\alias{of} -\alias{an} -\alias{Rscript,} -\alias{in} -\alias{order} -\alias{to} -\alias{prepare} -\alias{R} -\alias{environment} -\alias{run} -\alias{a} -\alias{script} -\alias{setting.} \title{Prepare the environment for a script} \usage{ scriptInit() } \value{ -Only side effect is used +No return value, called for side effects. } \description{ -Prepare the environment for a script +This function is called at the beginning of an Rscript, in order to +prepare the R environment to run in a script setting. } \examples{ -\dontrun{ +\donttest{ scriptInit() } } diff --git a/man/scriptName.Rd b/man/scriptName.Rd index e201352..51d7afe 100644 --- a/man/scriptName.Rd +++ b/man/scriptName.Rd @@ -20,7 +20,7 @@ When the R session was not initiated by a Rscript (i.e. there is no \code{--file Note that the function supports calling Rscript via \code{--file} or \code{-f} with \code{R}. This applies to cases where a Rscript, marked as executable, and is called from the command line. } \examples{ -\dontrun{scriptName()} +\donttest{scriptName()} } \seealso{ diff --git a/man/scriptPath.Rd b/man/scriptPath.Rd index 0631250..7303e39 100644 --- a/man/scriptPath.Rd +++ b/man/scriptPath.Rd @@ -20,7 +20,7 @@ When the R session was not initiated by a Rscript (i.e. there is no \code{--file Note that the function supports calling Rscript via \code{--file} or \code{-f} with \code{R}. This applies to cases where a Rscript, marked as executable, and is called from the command line. } \examples{ -\dontrun{scriptPath()} +\donttest{scriptPath()} } \seealso{ diff --git a/man/scriptSkeleton.Rd b/man/scriptSkeleton.Rd index 822a4a5..4f92501 100644 --- a/man/scriptSkeleton.Rd +++ b/man/scriptSkeleton.Rd @@ -9,9 +9,13 @@ scriptSkeleton(file = stdout()) \arguments{ \item{file}{Output file. By default the function writes to standard output.} } +\value{ +Invisibly returns the character vector of skeleton lines. +Called for its side effect of writing to \code{file}. +} \description{ Generate a Rscript with its skeleton } \examples{ -scriptSkeleton() +scriptSkeleton(file = file.path(tempdir(), "myscript.R")) } From 50d81e82111107a5454b9dc0da288c48d56969a2 Mon Sep 17 00:00:00 2001 From: Jitao David Zhang Date: Thu, 12 Feb 2026 10:46:45 +0100 Subject: [PATCH 3/9] suggestions made by Claude - though testing not working due to argInit error --- .Rbuildignore | 3 ++- .gitignore | 1 + man/scriptSkeleton.Rd | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 80e1dc9..bda3ed1 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -18,4 +18,5 @@ ^bin$ ^CRAN-SUBMISSION$ ^CRAN-PREPARATION\.md$ -^CRAN-FEEDBACK\.md$ \ No newline at end of file +^CRAN-FEEDBACK\.md$ +cran-fixes.patch diff --git a/.gitignore b/.gitignore index 5f2d382..690660e 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ symbols.rds *.dll .Rhistory .Rproj.user +cran-fixes.patch diff --git a/man/scriptSkeleton.Rd b/man/scriptSkeleton.Rd index 4f92501..382457b 100644 --- a/man/scriptSkeleton.Rd +++ b/man/scriptSkeleton.Rd @@ -11,7 +11,7 @@ scriptSkeleton(file = stdout()) } \value{ Invisibly returns the character vector of skeleton lines. -Called for its side effect of writing to \code{file}. + Called for its side effect of writing to \code{file}. } \description{ Generate a Rscript with its skeleton From 490fbf4bac40611740d40181f07cd715e16d3b1d Mon Sep 17 00:00:00 2001 From: Jitao David Zhang Date: Thu, 12 Feb 2026 10:48:31 +0100 Subject: [PATCH 4/9] ignore tar.gz files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 690660e..7ae88eb 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ symbols.rds .Rhistory .Rproj.user cran-fixes.patch +*.tar.gz From 90e22a1e88c019a3fe7b465406a162bd2fbe7a4a Mon Sep 17 00:00:00 2001 From: Jitao David Zhang Date: Thu, 12 Feb 2026 11:25:40 +0100 Subject: [PATCH 5/9] addressing the issues raised by the reviewer --- DESCRIPTION | 3 +- NAMESPACE | 1 + NEWS | 5 + NEWS.md | 101 ---- R/argparse.R | 14 +- R/parseFuncs.R | 2 +- R/ribiosArg.R | 10 +- R/zzz.R | 12 + man/argIsInit.Rd | 14 + man/argParse.Rd | 1 - man/parseFactor.Rd | 2 +- man/ribiosArg-package.Rd | 9 +- man/ribiosArg.Rd | 13 + .../00_pkg_src/ribiosArg/DESCRIPTION | 30 + .../00_pkg_src/ribiosArg/NAMESPACE | 29 + ribiosArg.Rcheck/00_pkg_src/ribiosArg/NEWS | 83 +++ .../00_pkg_src/ribiosArg/R/argparse.R | 209 +++++++ .../00_pkg_src/ribiosArg/R/debugging.R | 41 ++ .../00_pkg_src/ribiosArg/R/existArg.R | 32 ++ .../00_pkg_src/ribiosArg/R/getArg.R | 87 +++ .../00_pkg_src/ribiosArg/R/parseFuncs.R | 267 +++++++++ .../00_pkg_src/ribiosArg/R/ribiosArg.R | 9 + .../00_pkg_src/ribiosArg/R/scriptInit.R | 26 + .../00_pkg_src/ribiosArg/R/scriptName.R | 62 +++ .../00_pkg_src/ribiosArg/R/scriptSkeleton.R | 39 ++ ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/zzz.R | 12 + .../00_pkg_src/ribiosArg/README.md | 19 + .../ribiosArg/inst/Rscript/minimal.Rscript | 69 +++ .../Rscript/test-argParse-notstrict.Rscript | 21 + .../inst/Rscript/test-argParse.Rscript | 28 + .../ribiosArg/inst/include/ribios_arg.h | 33 ++ .../00_pkg_src/ribiosArg/man/argGet.Rd | 34 ++ .../00_pkg_src/ribiosArg/man/argGetPos.Rd | 36 ++ .../00_pkg_src/ribiosArg/man/argIsInit.Rd | 14 + .../00_pkg_src/ribiosArg/man/argParse.Rd | 62 +++ .../00_pkg_src/ribiosArg/man/existArg.Rd | 31 ++ .../00_pkg_src/ribiosArg/man/getArg.Rd | 33 ++ .../00_pkg_src/ribiosArg/man/isDebugging.Rd | 24 + .../ribiosArg/man/isIntDebugging.Rd | 17 + .../00_pkg_src/ribiosArg/man/makeFactor.Rd | 35 ++ .../00_pkg_src/ribiosArg/man/parseFactor.Rd | 49 ++ .../00_pkg_src/ribiosArg/man/parseFiles.Rd | 34 ++ .../00_pkg_src/ribiosArg/man/parseNumVec.Rd | 36 ++ .../00_pkg_src/ribiosArg/man/parsePairs.Rd | 48 ++ .../00_pkg_src/ribiosArg/man/parseStrings.Rd | 46 ++ .../ribiosArg/man/ribiosArg-package.Rd | 22 + .../00_pkg_src/ribiosArg/man/ribiosArg.Rd | 13 + .../00_pkg_src/ribiosArg/man/scriptInit.Rd | 21 + .../00_pkg_src/ribiosArg/man/scriptName.Rd | 31 ++ .../00_pkg_src/ribiosArg/man/scriptPath.Rd | 31 ++ .../ribiosArg/man/scriptSkeleton.Rd | 21 + .../00_pkg_src/ribiosArg/man/setDebug.Rd | 17 + .../00_pkg_src/ribiosArg/man/unsetDebug.Rd | 17 + .../00_pkg_src/ribiosArg/src/Makevars | 1 + .../00_pkg_src/ribiosArg/src/argparse.c | 86 +++ .../00_pkg_src/ribiosArg/src/argparse.h | 8 + .../00_pkg_src/ribiosArg/src/init.c | 36 ++ .../ribiosArg/tests/test_argParse.R | 15 + .../ribiosArg/tests/test_argPresent_uninit.R | 13 + .../00_pkg_src/ribiosArg/tests/test_getArg.R | 52 ++ .../ribiosArg/tests/test_parseNumVec.R | 19 + .../ribiosArg/tests/test_scriptName.R | 8 + ribiosArg.Rcheck/00check.log | 69 +++ ribiosArg.Rcheck/00install.out | 20 + ribiosArg.Rcheck/Rdlatex.log | 395 +++++++++++++ ribiosArg.Rcheck/ribiosArg-Ex.R | 284 ++++++++++ ribiosArg.Rcheck/ribiosArg-Ex.Rout | 370 +++++++++++++ ribiosArg.Rcheck/ribiosArg-Ex.pdf | Bin 0 -> 3611 bytes ribiosArg.Rcheck/ribiosArg-manual.log | 517 ++++++++++++++++++ ribiosArg.Rcheck/ribiosArg-manual.pdf | Bin 0 -> 125700 bytes ribiosArg.Rcheck/ribiosArg/DESCRIPTION | 31 ++ ribiosArg.Rcheck/ribiosArg/INDEX | 27 + ribiosArg.Rcheck/ribiosArg/Meta/Rd.rds | Bin 0 -> 1032 bytes ribiosArg.Rcheck/ribiosArg/Meta/features.rds | Bin 0 -> 123 bytes ribiosArg.Rcheck/ribiosArg/Meta/hsearch.rds | Bin 0 -> 973 bytes ribiosArg.Rcheck/ribiosArg/Meta/links.rds | Bin 0 -> 393 bytes ribiosArg.Rcheck/ribiosArg/Meta/nsInfo.rds | Bin 0 -> 476 bytes ribiosArg.Rcheck/ribiosArg/Meta/package.rds | Bin 0 -> 1026 bytes ribiosArg.Rcheck/ribiosArg/NAMESPACE | 29 + ribiosArg.Rcheck/ribiosArg/NEWS | 83 +++ ribiosArg.Rcheck/ribiosArg/R/ribiosArg | 27 + ribiosArg.Rcheck/ribiosArg/R/ribiosArg.rdb | Bin 0 -> 22993 bytes ribiosArg.Rcheck/ribiosArg/R/ribiosArg.rdx | Bin 0 -> 581 bytes .../ribiosArg/Rscript/minimal.Rscript | 69 +++ .../Rscript/test-argParse-notstrict.Rscript | 21 + .../ribiosArg/Rscript/test-argParse.Rscript | 28 + ribiosArg.Rcheck/ribiosArg/help/AnIndex | 24 + ribiosArg.Rcheck/ribiosArg/help/aliases.rds | Bin 0 -> 268 bytes ribiosArg.Rcheck/ribiosArg/help/paths.rds | Bin 0 -> 318 bytes ribiosArg.Rcheck/ribiosArg/help/ribiosArg.rdb | Bin 0 -> 37443 bytes ribiosArg.Rcheck/ribiosArg/help/ribiosArg.rdx | Bin 0 -> 626 bytes ribiosArg.Rcheck/ribiosArg/html/00Index.html | 72 +++ ribiosArg.Rcheck/ribiosArg/html/R.css | 130 +++++ .../ribiosArg/include/ribios_arg.h | 33 ++ ribiosArg.Rcheck/tests/startup.Rs | 4 + ribiosArg.Rcheck/tests/test_argParse.R | 15 + ribiosArg.Rcheck/tests/test_argParse.Rout | 26 + .../tests/test_argPresent_uninit.R | 13 + .../tests/test_argPresent_uninit.Rout | 26 + ribiosArg.Rcheck/tests/test_getArg.R | 52 ++ ribiosArg.Rcheck/tests/test_getArg.Rout | 27 + ribiosArg.Rcheck/tests/test_parseNumVec.R | 19 + ribiosArg.Rcheck/tests/test_parseNumVec.Rout | 26 + ribiosArg.Rcheck/tests/test_scriptName.R | 8 + ribiosArg.Rcheck/tests/test_scriptName.Rout | 29 + tests/test_argPresent_uninit.R | 13 + 106 files changed, 4562 insertions(+), 118 deletions(-) delete mode 100644 NEWS.md create mode 100644 R/zzz.R create mode 100644 man/argIsInit.Rd create mode 100644 man/ribiosArg.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/DESCRIPTION create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/NAMESPACE create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/NEWS create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/argparse.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/debugging.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/existArg.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/getArg.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/parseFuncs.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/ribiosArg.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptInit.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptName.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptSkeleton.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/zzz.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/README.md create mode 100755 ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/minimal.Rscript create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse-notstrict.Rscript create mode 100755 ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse.Rscript create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/include/ribios_arg.h create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGet.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGetPos.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argIsInit.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argParse.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/existArg.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/getArg.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isDebugging.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isIntDebugging.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/makeFactor.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFactor.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFiles.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseNumVec.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parsePairs.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseStrings.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg-package.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptInit.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptName.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptPath.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptSkeleton.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/setDebug.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/unsetDebug.Rd create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/Makevars create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/argparse.c create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/argparse.h create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/init.c create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argParse.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argPresent_uninit.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_getArg.R create mode 100644 ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_parseNumVec.R create mode 100755 ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_scriptName.R create mode 100644 ribiosArg.Rcheck/00check.log create mode 100644 ribiosArg.Rcheck/00install.out create mode 100644 ribiosArg.Rcheck/Rdlatex.log create mode 100644 ribiosArg.Rcheck/ribiosArg-Ex.R create mode 100644 ribiosArg.Rcheck/ribiosArg-Ex.Rout create mode 100644 ribiosArg.Rcheck/ribiosArg-Ex.pdf create mode 100644 ribiosArg.Rcheck/ribiosArg-manual.log create mode 100644 ribiosArg.Rcheck/ribiosArg-manual.pdf create mode 100644 ribiosArg.Rcheck/ribiosArg/DESCRIPTION create mode 100644 ribiosArg.Rcheck/ribiosArg/INDEX create mode 100644 ribiosArg.Rcheck/ribiosArg/Meta/Rd.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/Meta/features.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/Meta/hsearch.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/Meta/links.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/Meta/nsInfo.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/Meta/package.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/NAMESPACE create mode 100644 ribiosArg.Rcheck/ribiosArg/NEWS create mode 100644 ribiosArg.Rcheck/ribiosArg/R/ribiosArg create mode 100644 ribiosArg.Rcheck/ribiosArg/R/ribiosArg.rdb create mode 100644 ribiosArg.Rcheck/ribiosArg/R/ribiosArg.rdx create mode 100755 ribiosArg.Rcheck/ribiosArg/Rscript/minimal.Rscript create mode 100644 ribiosArg.Rcheck/ribiosArg/Rscript/test-argParse-notstrict.Rscript create mode 100755 ribiosArg.Rcheck/ribiosArg/Rscript/test-argParse.Rscript create mode 100644 ribiosArg.Rcheck/ribiosArg/help/AnIndex create mode 100644 ribiosArg.Rcheck/ribiosArg/help/aliases.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/help/paths.rds create mode 100644 ribiosArg.Rcheck/ribiosArg/help/ribiosArg.rdb create mode 100644 ribiosArg.Rcheck/ribiosArg/help/ribiosArg.rdx create mode 100644 ribiosArg.Rcheck/ribiosArg/html/00Index.html create mode 100644 ribiosArg.Rcheck/ribiosArg/html/R.css create mode 100644 ribiosArg.Rcheck/ribiosArg/include/ribios_arg.h create mode 100644 ribiosArg.Rcheck/tests/startup.Rs create mode 100644 ribiosArg.Rcheck/tests/test_argParse.R create mode 100644 ribiosArg.Rcheck/tests/test_argParse.Rout create mode 100644 ribiosArg.Rcheck/tests/test_argPresent_uninit.R create mode 100644 ribiosArg.Rcheck/tests/test_argPresent_uninit.Rout create mode 100644 ribiosArg.Rcheck/tests/test_getArg.R create mode 100644 ribiosArg.Rcheck/tests/test_getArg.Rout create mode 100644 ribiosArg.Rcheck/tests/test_parseNumVec.R create mode 100644 ribiosArg.Rcheck/tests/test_parseNumVec.Rout create mode 100755 ribiosArg.Rcheck/tests/test_scriptName.R create mode 100644 ribiosArg.Rcheck/tests/test_scriptName.Rout create mode 100644 tests/test_argPresent_uninit.R diff --git a/DESCRIPTION b/DESCRIPTION index a24edcb..859eb2b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,8 +8,7 @@ Authors@R: family = "Zhang", role = c("aut", "cre", "ctb"), email = "jitao_david.zhang@roche.com", - comment = c(ORCID="0000-0002-3085-0909")), - person("F.Hoffmann-La Roche AG", role="cph")) + comment = c(ORCID="0000-0002-3085-0909"))) Description: Provides functions to handle command-line arguments for R scripting. It enables building stand-alone R programs that accept and parse command-line options in 'BIOS' style. diff --git a/NAMESPACE b/NAMESPACE index e5a4b2c..2b444af 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -2,6 +2,7 @@ export(argGet) export(argGetPos) +export(argIsInit) export(argParse) export(argPresent) export(existArg) diff --git a/NEWS b/NEWS index 149119b..b607e64 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,8 @@ +2026-02-12: v1.5-1 + + Auto-initialize arg parser on package load in script mode (.onLoad in R/zzz.R) + + Add R-level guards in argPresent, argGet, and argGetPos to return safe defaults when the parser is uninitialized + + Export argIsInit() for users to check parser initialization status + 2015-09-04: v1.1-18 + rarg_parse: fixed a bug caused by passing SEXP as a size_t object diff --git a/NEWS.md b/NEWS.md deleted file mode 100644 index 589bb47..0000000 --- a/NEWS.md +++ /dev/null @@ -1,101 +0,0 @@ -# ribiosArg 1.5.0 - -* Initial CRAN submission -* Package prepared for CRAN submission with comprehensive documentation -* Depends on ribiosUtils (on CRAN) and uses its C headers via LinkingTo - -# ribiosArg 1.1.18 (2015-09-04) - -* `rarg_parse`: fixed bug caused by passing SEXP as a size_t object - -# ribiosArg 1.1.17 (2015-06-23) - -* `argParse` returns invisible NULL in all situations -* `argGetPos` and `argGet` returns default value in debugging mode - -# ribiosArg 1.1.16 (2015-06-08) - -* `parseNumVec` bug fix: returns failVal when input str is NULL - -# ribiosArg 1.1.15 (2015-02-09) - -* `makeFactor`: add 'verbose=FALSE' option - -# ribiosArg 1.1.14 (2015-01-12) - -* `argParse`: works with -e and --args options of R and Rscript - -# ribiosArg 1.1.13 (2014-10-07) - -* `argParse`: works with latest Rscript - -# ribiosArg 1.1.12 (2014-08-15) - -* `argParse`: add 'strict=TRUE' option for extra parameter handling - -# ribiosArg 1.1.11 (2014-06-23) - -* argparse C code: now aware of format strings in die/usage - -# ribiosArg 1.1.10 (2014-05-09) - -* `parseStrings` and `parsePairs` return NULL for NULL input -* Export `parseFactor` and `makeFactor` - -# ribiosArg 1.1.7 (2014-03-11) - -* `rarg_get` checks initialization to avoid segmentation error - -# ribiosArg 1.1.6 (2013-10-16) - -* `argParse` prints command line on parse failure - -# ribiosArg 1.1.5 (2013-07-29) - -* Add `parseStrings` and `parsePairs` -* ribiosArg now depends on ribiosUtils - -# ribiosArg 1.1.4 (2013-07-14) - -* `argPresent` returns FALSE if arg_init not called -* `argGet` prints error and returns NULL if arg_init not called - -# ribiosArg 1.1.3 (2013-05-15) - -* Add 'default' parameter to `argGet` and `argGetPos` -* Move `scriptInit()` to ribiosUtils - -# ribiosArg 1.1.2 (2013-01-28) - -* `argParse`: optargs and reqargs can be NULL -* Replace log.h module with local mimics - -# ribiosArg 1.1.1 (2013-01-23) - -* Add `scriptInit` to prepare R for the script - -# ribiosArg 1.1.0 (2013-01-04) - -* Add BIOS-style command-line parser: `argParser`, `argGet`, `argGetPos`, `argPresent` - -# ribiosArg 1.0.5 (2012-01-24) - -* Add `RscriptName` function to get current script file name - -# ribiosArg 1.0.4 (2011-12-19) - -* `parseNumVec` accepts NULL as expLen for variable-length vectors - -# ribiosArg 1.0.3 (2011-12-15) - -* `getArg` parameter handling improvements -* Add tests folder for consistent behavior testing - -# ribiosArg 1.0.2 (2011-10-10) - -* `getArg` differentiates options and negative numbers -* `parseNumVec` removes leading and trailing quotes - -# ribiosArg 1.0.1 (2011-10-04) - -* `parseNumVec` suppresses warnings during string-to-number conversion diff --git a/R/argparse.R b/R/argparse.R index 1e5d77f..8978670 100644 --- a/R/argparse.R +++ b/R/argparse.R @@ -1,5 +1,4 @@ #' Parser of command-line parameters in BIOS style -#' @aliases argIsInit #' @aliases argPresent #' #' @param optargs String describing optional arguments. Syntax: \code{[,paramcnt1] [,paramcnt2]\dots}. Example: \dQuote{verbose outfile,1} means the command line has the syntax \code{prog [-verbose] [outfile name]}. It can be an empty string to express \dQuote{no options}. The value for \code{paramcnt} is 0. @@ -70,8 +69,8 @@ argParse <- function(optargs, reqargs, usage=paste(scriptName(), "-h"), strict=T efind <- which(isE) allComm <- allComm[-(1:(efind+1))] } else { - stop("This should not happen: no parameters in the form of '-f' or '--f' is detected. Please contact the developer") - } + return(invisible(NULL)) + } comm <- allComm[!grepl("^--", allComm)] ## the following code was valid till R-3.0.x. ## if("--args" %in% allComm) { @@ -114,6 +113,10 @@ argParse <- function(optargs, reqargs, usage=paste(scriptName(), "-h"), strict=T } } +#' Check whether the argument parser has been initialized +#' +#' @return Logical, \code{TRUE} if \code{argParse} has been called, \code{FALSE} otherwise. +#' @export argIsInit <- function() .Call(C_rarg_isInit) #' Test whether the given option is present in the command line or not @@ -127,6 +130,7 @@ argPresent <- function(opt) { message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode. FALSE is returned") return(FALSE) } + if(!isTRUE(argIsInit())) return(FALSE) .Call(C_rarg_present, opt) } @@ -154,7 +158,8 @@ argGetPos <- function(opt, ind=1L, default=NULL, choices=NULL) { if(isDebugging()) { message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode. Default value is returned") return(default) - } + } + if(!isTRUE(argIsInit())) return(default) if(argPresent(opt)) { res <- .Call(C_rarg_getPos, opt,as.integer(ind)) if(!is.null(choices) && !res %in% choices) @@ -190,6 +195,7 @@ argGet <- function(opt, default=NULL, choices=NULL) { message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode. Default value is returned") return(default) } + if(!isTRUE(argIsInit())) return(default) if(argPresent(opt)) { res <- .Call(C_rarg_get, opt) if(!is.null(choices) && !res %in% choices) { diff --git a/R/parseFuncs.R b/R/parseFuncs.R index 29a732b..d31bbe6 100644 --- a/R/parseFuncs.R +++ b/R/parseFuncs.R @@ -204,7 +204,7 @@ makeFactor <- function(groups, levels=NULL, make.names=TRUE, verbose=FALSE) { #' #' groups <- c("ATest", "Control", "Control", "ATest", "BTest") #' levels <- c("Control", "ATest") -#' makeFactor(groups, levels) +#' try(makeFactor(groups, levels)) #' } #' parseFactor <- function(str, rlevels=NULL, make.names=TRUE, collapse=",") { ## CL=command line diff --git a/R/ribiosArg.R b/R/ribiosArg.R index 46e553c..2f9eba7 100644 --- a/R/ribiosArg.R +++ b/R/ribiosArg.R @@ -1,7 +1,9 @@ -#' Command-line argument handling for R scripting -#' @docType package -#' @description Provides command-line argument handling for R scripting +#' @keywords internal +"_PACKAGE" + +#' ribiosIO +#' ribiosIO provides Command-line argument handling for R scripting #' @author Jitao David Zhang #' @useDynLib ribiosArg, .registration=TRUE, .fixes="C_" -#' @name ribiosArg-package +#' @name ribiosArg NULL diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..7d6552e --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,12 @@ +.onLoad <- function(libname, pkgname) { + if (!interactive() && !isDebugging()) { + allComm <- commandArgs(FALSE) + isScript <- any(grepl("^--file=", allComm)) || any(grepl("^-f$", allComm)) + if (isScript) { + tryCatch( + argParse(optargs = "", reqargs = "", strict = FALSE), + error = function(e) invisible(NULL) + ) + } + } +} diff --git a/man/argIsInit.Rd b/man/argIsInit.Rd new file mode 100644 index 0000000..ad57298 --- /dev/null +++ b/man/argIsInit.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/argparse.R +\name{argIsInit} +\alias{argIsInit} +\title{Check whether the argument parser has been initialized} +\usage{ +argIsInit() +} +\value{ +Logical, \code{TRUE} if \code{argParse} has been called, \code{FALSE} otherwise. +} +\description{ +Check whether the argument parser has been initialized +} diff --git a/man/argParse.Rd b/man/argParse.Rd index ec97d77..991b965 100644 --- a/man/argParse.Rd +++ b/man/argParse.Rd @@ -2,7 +2,6 @@ % Please edit documentation in R/argparse.R \name{argParse} \alias{argParse} -\alias{argIsInit} \alias{argPresent} \title{Parser of command-line parameters in BIOS style} \usage{ diff --git a/man/parseFactor.Rd b/man/parseFactor.Rd index 5beea99..0bf8301 100644 --- a/man/parseFactor.Rd +++ b/man/parseFactor.Rd @@ -43,7 +43,7 @@ makeFactor(groups, levels) groups <- c("ATest", "Control", "Control", "ATest", "BTest") levels <- c("Control", "ATest") -makeFactor(groups, levels) +try(makeFactor(groups, levels)) } } diff --git a/man/ribiosArg-package.Rd b/man/ribiosArg-package.Rd index ec569a6..238c014 100644 --- a/man/ribiosArg-package.Rd +++ b/man/ribiosArg-package.Rd @@ -2,11 +2,10 @@ % Please edit documentation in R/ribiosArg.R \docType{package} \name{ribiosArg-package} -\alias{ribiosArg} \alias{ribiosArg-package} -\title{Command-line argument handling for R scripting} +\title{ribiosArg: Argument Handling for Command-Line, Stand-Alone R Scripts} \description{ -Provides command-line argument handling for R scripting +Provides functions to handle command-line arguments for R scripting. It enables building stand-alone R programs that accept and parse command-line options in 'BIOS' style. Zhang (2025) \url{https://github.com/bedapub/ribiosArg}. } \seealso{ Useful links: @@ -17,5 +16,7 @@ Useful links: } \author{ -Jitao David Zhang +\strong{Maintainer}: Jitao David Zhang \email{jitao_david.zhang@roche.com} (\href{https://orcid.org/0000-0002-3085-0909}{ORCID}) [contributor] + } +\keyword{internal} diff --git a/man/ribiosArg.Rd b/man/ribiosArg.Rd new file mode 100644 index 0000000..d7c1f2f --- /dev/null +++ b/man/ribiosArg.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ribiosArg.R +\name{ribiosArg} +\alias{ribiosArg} +\title{ribiosIO +ribiosIO provides Command-line argument handling for R scripting} +\description{ +ribiosIO +ribiosIO provides Command-line argument handling for R scripting +} +\author{ +Jitao David Zhang +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/DESCRIPTION b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/DESCRIPTION new file mode 100644 index 0000000..88c336e --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/DESCRIPTION @@ -0,0 +1,30 @@ +Package: ribiosArg +Type: Package +Title: Argument Handling for Command-Line, Stand-Alone R Scripts +Version: 1.5.0 +Date: 2026-01-24 +Authors@R: + c(person(given = "Jitao David", + family = "Zhang", + role = c("aut", "cre", "ctb"), + email = "jitao_david.zhang@roche.com", + comment = c(ORCID="0000-0002-3085-0909"))) +Description: Provides functions to handle command-line arguments for R + scripting. It enables building stand-alone R programs that accept and + parse command-line options in 'BIOS' style. + Zhang (2025) . +Depends: R (>= 3.4.0), ribiosUtils +LinkingTo: ribiosUtils +Imports: utils +Suggests: testthat +License: GPL-3 +URL: https://github.com/bedapub/ribiosArg +BugReports: https://github.com/bedapub/ribiosArg/issues +Encoding: UTF-8 +LazyLoad: yes +RoxygenNote: 7.3.3 +NeedsCompilation: yes +Packaged: 2026-02-12 10:18:21 UTC; david +Author: Jitao David Zhang [aut, cre, ctb] (ORCID: + ) +Maintainer: Jitao David Zhang diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/NAMESPACE b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/NAMESPACE new file mode 100644 index 0000000..2b444af --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/NAMESPACE @@ -0,0 +1,29 @@ +# Generated by roxygen2: do not edit by hand + +export(argGet) +export(argGetPos) +export(argIsInit) +export(argParse) +export(argPresent) +export(existArg) +export(getArg) +export(isDebugging) +export(isIntDebugging) +export(makeFactor) +export(parseFactor) +export(parseFiles) +export(parseNumVec) +export(parsePairs) +export(parseStrings) +export(scriptInit) +export(scriptName) +export(scriptPath) +export(scriptSkeleton) +export(setDebug) +export(unsetDebug) +importFrom(ribiosUtils,extname) +importFrom(ribiosUtils,qqmsg) +importFrom(ribiosUtils,trim) +importFrom(utils,untar) +importFrom(utils,unzip) +useDynLib(ribiosArg, .registration=TRUE, .fixes="C_") diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/NEWS b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/NEWS new file mode 100644 index 0000000..b607e64 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/NEWS @@ -0,0 +1,83 @@ +2026-02-12: v1.5-1 + + Auto-initialize arg parser on package load in script mode (.onLoad in R/zzz.R) + + Add R-level guards in argPresent, argGet, and argGetPos to return safe defaults when the parser is uninitialized + + Export argIsInit() for users to check parser initialization status + +2015-09-04: v1.1-18 + + rarg_parse: fixed a bug caused by passing SEXP as a size_t object + +2015-06-23: v1.1-17 + + argParse returns invisible NULL in all situations + + argGetPos and argGet returns default value when running in debugging mode + +2015-06-08: v1.1-16 + + parseNumVec solves a bug when the input str is NULL the returned value is garanteed to be failVal + +2015-02-09: v1.1-15 + + makeFactor: add 'verbose=FALSE' option. Warning messages are only printed if it is set to TRUE. + +2015-01-12: v1.1-14 + + argParse: the function now works with -e and --args options of R and Rscript + + Pending: writing tests to make sure argParse works (see ~/sandbox/knitr-example/Makefile for examples) + +2014-10-07: v1.1-13 + + argParse: the function now works with the latest Rscript. The change is that the script files are more consistently handled by Rscript (in the form of Rscript FILE) and R (R -f FILE or R --file=FILE). The function has been updated to adapt to this change. + +2014-08-15: v1.1-12 + + argParse: add an extra option 'strict=TRUE'. If set to FALSE, the function will return command-line parameters that were not appended with a prefix (e.g. -prefix PARAMETER). + + Note that argParse's return value has changed: by default it returns an invisible \code{NULL} (before it returns the invisible length of valid parameters). If strict=TRUE, it returns the extra parameters as an invisible character vector + +2014-06-23: v1.1-11 + + argparse: the C code is now aware of the format strings in die/usage. + + The memory leakage problem is still not solved. When a program misses some parameters, it now prints the correct diagnostic information, but then dies reporting "memory not mapped". It is suspected (not confirmed though) that this may be caused by unfreed pointers when the program exists. It remains to be fixed. + +2014-05-09: v1.1-10 + + parseStrings and parsePairs return NULL in case the input parameter is NULL. + + Export parseFactor and makeFactor + +2014-03-11: v1.1-7 + + rarg_get checks initialization to avoid segmentation error when called by a script + +2013-10-16: v1.1-6 + + argParse function prints the command line if fails to parse the needed parameters. It helps debugging the input. + +2013-07-29: v1.1-5 + + add parseStrings and parsePairs + + From v1.1-5 ribiosArgs depends on ribiosUtils. + +2013-07-14: v1.1-4 + + argPresent returns FALSE if arg_init and/or arg_initTry has not been called + + argGet prints an error and returns NULL if arg_init and/or arg_initTry has not been called + + +2013-05-15: v1.1-3 + + Add new paramter 'default' to argGet and argGetPos to make the function safer in case the parameter is not specificied + + Move scriptInit() to ribiosUtils + +2013-01-28: v1.1-2 + + argParse: now optargs and reqargs can be set to NULL without causing the R session to crash + + The log.h module of bios has been replaced by the local mimics, in order not to crash the R session in case problems. Note that however arg_init() and arg_try() still must be called before argGet() and argPresent(). Otherwise the program will end reporting the segfault "memory not mapped". + +2013-01-23: v1.1-1 + + Add scriptInit to prepare R for the script + +2013-01-04: v1.1-0 + + Add BIOS-style command-line parser: argParser, argGet, argGetPos and argPresent. + +2012-01-24: v1.0-5 + + Add RscriptName function to get the file name of the current Rscript + +2011-12-19: v1.0-4 + + The parseNumVec parameter accepts NULL as expLen value, in order to parse variable-length number vectors + +2011-12-15: v1.0.3 + + The onlyArg and/or missingArg parameter of the getArg function can be set to NULL now (in previous versions this would cause an error) + + Add tests folder to keep consistent behaviours of important functions (now getArg is under control, parseNumVec and existArg shall be tested similarly in future releases) + +2011-10-10: v1.0.2 + + (Important) getArg differentiates options (starting with a minus sign AND a non-numeric character, namely 0-9 or the dot) and negative numbers (starting with a minus sign, followed by numeric characters). For instance, "-a" is an option, but the "-3,4" in "-a -3,4" will be treated as value for "a". Arguments, which contain at least one character which is not number or punctuation characters (see ?regex), will be considered as an option (parameter) instead of a value, for instance "-3way". + + parseNumVec removes leading and training quotes when existing. + + +2011-10-04: v1.0.1 + + parseNumVec suppresses warnings during the attempts to convert strings to numbers diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/argparse.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/argparse.R new file mode 100644 index 0000000..70412fa --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/argparse.R @@ -0,0 +1,209 @@ +#' Parser of command-line parameters in BIOS style +#' @aliases argPresent +#' +#' @param optargs String describing optional arguments. Syntax: \code{[,paramcnt1] [,paramcnt2]\dots}. Example: \dQuote{verbose outfile,1} means the command line has the syntax \code{prog [-verbose] [outfile name]}. It can be an empty string to express \dQuote{no options}. The value for \code{paramcnt} is 0. +#' @param reqargs String describining required arguments. Syntax: \code{ \dots}. Example: \dQuote{infile outfile} means the command line has the syntax \code{prog [-infile ]infile [-outfile ]coutfile}. Even if it is empty, it is checked that at least one non-optional value is given. +#' @param usage A character string to be printed if the command-line option parsing fails +#' @param strict Logical, are extra un-prefixed parameters allowed? If set to \code{TRUE}, the un-prefixed parameters (which must be at the end of the command line) will be returned as a character vector. +#' +#' @details +#' \code{argParse} must be called before \code{argGet},\code{argGetPos} +#' , \code{argPresent}, or \code{argGetDefault}. It checks whether the command line syntax agrees +#' with the specification of \code{optargs} and \code{reqargs}. If not, +#' the \code{usage} message is printed and the program exists. +#' +#' \code{argPresent} returns a boolean value indicating whether the option is present or not. +#' +#' If the syntax was found correct, \code{argGetPos} can be called to +#' fetch the \code{ind}th value of the option \code{opt} (indexing from 1). For instance, +#' if the following option \code{-ranges 3 5} is defined, +#' argGetPos(\dQuote{range}, 2) returns \code{5}. \code{argGet} is +#' a shortcut to fetch the first element. If the opt is missing, the +#' \code{default} value will be returned. +#' +#' @return +#' \code{argParse} is used for the side effects. If \code{strict} is set to +#' \code{TRUE}, an invisible \code{NULL} is returned; otherwise, extra +#' un-prefixed parameters are returned as an invisible character vector +#' +#' \code{argGet} and \code{argGetPos} returns a character +#' string. \code{argPresent} returns a boolean value. +#' +#' In case of any error (wrong syntax, or not-existing option) the R +#' session quits while printing the error message. +#' +#' @importFrom ribiosUtils qqmsg +#' @useDynLib ribiosArg, .registration=TRUE, .fixes="C_" +#' +#' @examples +#' \donttest{ +#' argParse("verbose threshold,2", "infile outfile", +#' usage="prog [-infile ]infile [-outfile ]outfile [-verbose] [-threshold MIN MAX]") +#' argIsInit() +#' argPresent("verbose") +#' } +#' +#' @export +argParse <- function(optargs, reqargs, usage=paste(scriptName(), "-h"), strict=TRUE) { + if(isDebugging()) { + message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode") + return(invisible(NULL)) + } + allComm <- commandArgs(FALSE) + isFile <- grepl("^--file=", allComm) + isF <- grepl("^-f", allComm) + isE <- grepl("^-e", allComm) + isArgs <- grepl("^--args", allComm) + isE <- grepl("^-e", allComm) + if( any(isFile) ) { + find <- which(isFile) + allComm[find] <- gsub("^--file=", "", allComm[find]) + allComm <- allComm[-c(1:(find-1))] + } else if (any(isF)) { + find <- which(isF) + allComm <- allComm[-(1:find)] + } else if (any(isArgs)) { + find <- which(isArgs) + allComm <- allComm[-(1:find)] + } else if (any(isE)) { + efind <- which(isE) + allComm <- allComm[-(1:(efind+1))] + } else { + stop("This should not happen: no parameters in the form of '-f' or '--f' is detected. Please contact the developer") + } + comm <- allComm[!grepl("^--", allComm)] + ## the following code was valid till R-3.0.x. + ## if("--args" %in% allComm) { + ## indFile <- grep("^--file=", allComm) + ## allComm[indFile] <- gsub("^--file=", "", allComm[indFile]) ## script name + ## allComm <- allComm[-c(1:(indFile-1))] + ## comm <- allComm[!grepl("^--", allComm)] + ## } else { + ## comm <- allComm[-c(1:2)] + ## } + if(is.null(optargs)) optargs <- "" + if(is.null(reqargs)) reqargs <- "" + argc <- as.integer(length(comm)) + usage <- paste(usage, + ifelse(grepl("\n$", usage), "", "\n"), + "\n[Last call: ", + paste(commandArgs(trailingOnly=FALSE), collapse=" "), + "]\n", + sep="") + res <- .Call(C_rarg_parse, + argc, + as.character(comm), + as.character(optargs), + as.character(reqargs), + as.character(usage)) + + if(res<0) + qqmsg() + + if(strict) { + if(argc != res) + qqmsg() + return(invisible(NULL)) + } else { + if(argc >= (res+1)) { + return(invisible(comm[(res+1):argc])) + } else { + return(invisible(NULL)) + } + } +} + +#' Check whether the argument parser has been initialized +#' +#' @return Logical, \code{TRUE} if \code{argParse} has been called, \code{FALSE} otherwise. +#' @export +argIsInit <- function() .Call(C_rarg_isInit) + +#' Test whether the given option is present in the command line or not +#' +#' @param opt Character string, option name +#' +#' @rdname argParse +#' @export +argPresent <- function(opt) { + if(isDebugging()) { + message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode. FALSE is returned") + return(FALSE) + } + if(!isTRUE(argIsInit())) return(FALSE) + .Call(C_rarg_present, opt) +} + +#' Parse an argument with the given position +#' +#' Get the value of an named argument with the given position +#' +#' @param opt name of the argument to be parsed +#' @param ind index of the argument to be parsed, starting from 1. +#' @param default default values to be returned if the argument is not provided +#' @param choices a character vector of accepted values; if a string outside the vector is provided, the function will stop and print error message +#' +#' @details The parsing is performed at C-level. If the argument accepts only one value, users can also call argGet(opt, default=NULL, choices=NULL) +#' +#' @return A character string representing the value of the argument +#' +#' @author Jitao David Zhang +#' @seealso \code{\link{argParse}}, \code{\link{argGet}}, and \code{\link{argPresent}} +#' +#' @examples +#' \donttest{argGetPos("thresholds", ind=2)} +#' +#' @export +argGetPos <- function(opt, ind=1L, default=NULL, choices=NULL) { + if(isDebugging()) { + message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode. Default value is returned") + return(default) + } + if(!isTRUE(argIsInit())) return(default) + if(argPresent(opt)) { + res <- .Call(C_rarg_getPos, opt,as.integer(ind)) + if(!is.null(choices) && !res %in% choices) + stop(sprintf("Option '%s' accepts only following values: %s", + opt, paste(choices, collapse=","))) + } else { + res <- default + } + return(res) +} + +#' Parse an argument +#' +#' Get the value of an named argument +#' +#' @param opt name of the argument to be parsed +#' @param default default values to be returned if the argument is not provided +#' @param choices a character vector of accepted values; if a string outside the vector is provided, the function will stop and print error message +#' +#' @details The parsing is performed at C-level. It is an abbreiviation of argGetPos(opt, ind=1, default=NULL, choices=NULL) +#' +#' @return A character string representing the value of the argument +#' +#' @author Jitao David Zhang +#' @seealso \code{\link{argParse}}, \code{\link{argGetPos}}, and \code{\link{argPresent}} +#' +#' @examples +#' \donttest{argGet("infile")} +#' +#' @export +argGet <- function(opt, default=NULL, choices=NULL) { + if(isDebugging()) { + message("[DEBUGGIING] The script is running in an interactive session, e.g. debugging mode. Default value is returned") + return(default) + } + if(!isTRUE(argIsInit())) return(default) + if(argPresent(opt)) { + res <- .Call(C_rarg_get, opt) + if(!is.null(choices) && !res %in% choices) { + stop(sprintf("Option '%s' accepts only following values: %s", + opt, paste(choices, collapse=","))) + } + } else { + res <- default + } + return(res) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/debugging.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/debugging.R new file mode 100644 index 0000000..a1cc061 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/debugging.R @@ -0,0 +1,41 @@ +#' Test whether the environment is set for debugging +#' +#' @return A logical value +#' @seealso \code{\link{setDebug}} and \code{\link{unsetDebug}} +#' +#' @examples +#' isDebugging() +#' unsetDebug() +#' isDebugging() +#' setDebug() +#' +#' @export +isDebugging <- function() Sys.getenv("RIBIOS_SCRIPT_DEBUG") != "" + +#' Test whether the environment is set for debugging, or it's an interactive session +#' +#' @return A logical value +#' @seealso \code{\link{isDebugging}} +#' +#' @export +isIntDebugging <- function() isDebugging() || interactive() + +#' Set the enrivonment for debugging +#' +#' @return A logical value, whether the setting was susccessful or not +#' @seealso \code{\link{isDebugging}} and \code{\link{unsetDebug}} +#' @export +setDebug <- function() Sys.setenv(RIBIOS_SCRIPT_DEBUG="TRUE") + +#' Remove the debugging flag of the the enrivonment +#' +#' @return A logical value, whether the removal was successful or not +#' @seealso \code{\link{isDebugging}} and \code{\link{setDebug}} +#' @export +unsetDebug <- function() Sys.unsetenv("RIBIOS_SCRIPT_DEBUG") + + +rscriptSkeleton <- function(file=stdout) { + backbone <- "#!/usr/bin/env Rscript" + suppressMessages() +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/existArg.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/existArg.R new file mode 100644 index 0000000..1648ed1 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/existArg.R @@ -0,0 +1,32 @@ +#' Test if named arguments exists +#' +#' @param args Argument names, without leading minus sign +#' @details Options are those arguments with a leading minus sign +#' (e.g. "-opt"). This function tells whether queried options exist in +#' the argument list. +#' @return A vector of logicals, indicating whether the arguments exist +#' @seealso \code{\link{getArg}} +#' @export +#' @examples +#' comm <- paste(c("Rscript --vanilla -e", "'", "library(ribiosArg);", +#' "existArg(c(\"opt\", \"opt2\", \"opt3\"))", "'", +#' "-opt abc -opt3"), collapse=" ") +#' system(comm) +existArg <- function(args) { + argPattern <- paste("^-", args, "$", sep="") + + ## allArgs <- c("R", "-f", "test.R", "-infile", "a.file", "b.file", "-outfile", "o.file", "o2.file", "-value", "2", "3", "-hey", "-hallo") + ## allArgs <- c("/apps/bi/apps/R/R-2.11.1/bin/exec/R", "-f", "drawHeatmap.R") + allArgs <- commandArgs(trailingOnly=FALSE) + + argInd <- lapply(argPattern, function(x) grep(x, allArgs)) + argIndL <- sapply(argInd, length) + res <- vector("logical", length(args)) + res[argIndL==1L] <- TRUE + if(any(argIndL>1)) { + warning("Multiple values found:", paste(argPattern[argIndL>1], collapse="\t"), "\n") + res[argIndL>1L] <- TRUE + } + names(res) <- args + return(res) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/getArg.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/getArg.R new file mode 100644 index 0000000..79c2e7b --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/getArg.R @@ -0,0 +1,87 @@ +#' An R-implementation of getting named aguments +#' +#' This function is out-dated. Please use \code{argparse} instead. +#' +#' Options are those arguments with a leading minus sign. They can +#' have one or more values following them, which will be taken as the value +#' of the option. If no such values are availble, user could decide how to +#' interpret the option by setting the \code{onlyArg} parameter. Similarly, +#' missing options can be handled by \code{missingArg} +#' +#' From version 1.0.3 \code{onlyArg} and \code{missingArg} accepts \code{NULL} as inputs. +#' +#' @param args Character strings, named arguments +#' @param onlyArg Any type, What value should be returned if only the option is available and no value has been provided +#' @param missingArg Any type, What value should be returned if the option is not available +#' +#' @return A list when more than one option were queried; or a vector if only one option was queried. +#' @seealso \code{\link{existArg}} +#' +#' @export +#' +getArg <- function(args, onlyArg=FALSE, missingArg=FALSE) { + .Deprecated("argparse", package="ribiosArg") + argPattern <- paste("^-", args, "$", sep="") + + ## for testing purporses + ## allArgs <- c("R", "-f", "test-ab.R", "-infile", "a.file", "b.file", "-outfile", "o.file", + ## "o2.file", "-value", "2", "3", "-hey", "-hallo") + ## allArgs <- c("/apps/bi/apps/R/R-2.11.1/bin/exec/R", "-f", "drawHeatmap.R") + + ## add support of NULL: note that assigning a list item to NULL will actually remove that item + + oaNN <- !is.null(onlyArg) + maNN <- !is.null(missingArg) + + allArgs <- commandArgs(trailingOnly=FALSE) + + argAllInd <- grep("^-[^\\.0-9]", allArgs) ## note that negative numbers are excluded + argNumStart <- grep("^-[\\.0-9]+[^[:punct:]0-9]", allArgs); + argAllInd <- c(argAllInd, argNumStart) + + res <- vector("list", length(argPattern)) + names(res) <- args + argInd <- lapply(argPattern, function(x) grep(x, allArgs)) + argIndL <- sapply(argInd, length) + argRightInd <- argIndL==1L + if(any(argIndL==0)) { + nof <- which(argIndL==0L) + for(i in seq(along=nof)) + if(maNN) + res[[ nof[i] ]] <- missingArg + } + if(any(argIndL>1)) + warning("Multiple values found:", paste(argPattern[argIndL>1], collapse="\t"), "\n") + + if(all(!argRightInd)) { + if(length(args)==1) + return(res[[1]]) + return(res) + } + argStart <- unlist(argInd[argRightInd])+1L + ## argEnd: either next arg or end of the arg string + argEndCan <- c(argAllInd, length(allArgs)+1) + + ari <- which(argRightInd) + for(i in seq(along=argStart)) { + d <- argEndCan - argStart[i] + if(any(d==0)) { + if(oaNN) + res[[ ari[i] ]] <- onlyArg + } else if(!any(d>0)) { + if(maNN) + res[[ ari[i] ]] <- missingArg + } else { + res[[ ari[i] ]] <- allArgs[argStart[i]:(min(d[d>0])+argStart[i]-1L)] + } + } + + + if(length(res)==1) + res <- res[[1]] + if(length(res)==0) + return(FALSE) + + return(res) + +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/parseFuncs.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/parseFuncs.R new file mode 100644 index 0000000..29a732b --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/parseFuncs.R @@ -0,0 +1,267 @@ +#' Parse a character string into a numveric vector +#' +#' Numeric vectors can be given as arguments in two ways: (1) separated by +#' blanks or (2) separated by other common separators, such as comma +#' (,). This function parses a string, or a string vector into a numeric +#' vector of expected length. In addition it is failure safe: user can +#' specify the return value in case the parsing was not successful, +#' +#' The input value mostly comes from return values of the \code{\link{argGet}} function. + +#' @param str A character string +#' @param expLen Integer or \code{NULL}, Expected length of the numeric vector. When set to NULL, the numeric vector can be of variable length. +#' @param failVal If the parsing failed (for example length not correct, or non-numeric values were provided, this value will be returned +#' @param sep Separator in the character string, default "," +#' +#' @return A numeric vector of the parsed values, or \code{failVal} if parsing fails. +#' @seealso \code{\link{argGet}} +#' +#' @export +#' @examples +#' parseNumVec("3,7,9", expLen=3) +parseNumVec <- function(str, expLen=2, failVal=c(5,5), sep=",") { + ## for cases like 2, 2 (note tht extra blank after the comma) + if(is.null(str)) + return(failVal) + + str <- paste(str, collapse=sep) + + ## remove quotings if any + str <- gsub("\"", "", str) + + if(length(str)==1) { + str <- strsplit(str, sep)[[1]] + } + str <- str[str!=""] + + isNum <- suppressWarnings(all(!is.na(as.numeric(str)))) + if(!is.null(expLen)) { + isNum <- isNum && length(str) == expLen + } + if(isNum) { + return(as.numeric(str)) + } else { + return(failVal) + } +} + +#' Parse a character string into string vectors +#' +#' This function parses collapsed multiple options into a vector of +#' character strings. Each option is optionally trimmed of leading and tailing empty +#' spaces given by \code{trim}. See examples. +#' +#' @details +#' In case of multiple separators, they can be given by concatenating +#' with piple signs, e.g. \code{,|\\t}. +#' If input string is \code{NULL}, the function returns \code{NULL}. This +#' can be useful in case the parameter is optional and not specified. +#' +#' @param str A character string to be parsed +#' @param collapse Character(s) used in the character string to concatenate strings +#' @param trim Logical, whether additional spaces should be trimmed +#' @param ... Further parameters passed to \code{\link[ribiosUtils]{trim}} for fine-tuning of trimming +#' +#' @return A vector of character strings +#' @seealso \code{\link{strsplit}}, \code{\link[ribiosUtils]{trim}} +#' @importFrom ribiosUtils trim +#' @export +#' @examples +#' parseStrings("veni, vidi, vici") +#' parseStrings("veni, vidi, vici", trim=FALSE) +#' parseStrings("I came, I saw, I conquered") +#' +#' # options are trimmed +#' parseStrings("a,b,\tc,d\n") +#' # it works also with only one option +#' parseStrings("a") +#' # more than one separators +#' parseStrings("a,b,c;d", collapse=",|;") +parseStrings <- function(str, collapse=",", trim=TRUE, ...) { + if(is.null(str)) return(NULL) + res <- strsplit(str, collapse)[[1]] + if(trim) + res <- sapply(res, trim, ...) + return(res) +} + + +#' Parse key-value pairs from a character string +#' +#' The function parses parameters in the form of +#' \code{KEY1=VAL1,KEY2=VAL2,KEY3=VAL3} into \code{data.frame}. +#' +#' If input string is \code{NULL}, the function returns \code{NULL}. This +#' can be useful in case the parameter is optional and not specified. +#' @param str Character string +#' @param collapse Collapse character used in the string +#' @param sep Seperator used in the string +#' @param colnames Column names of the returned \code{data.frame} +#' @param trim Logical, whether additional spaces should be trimmed +#' @param ... Further parameters passed to \code{\link[ribiosUtils]{trim}} for fine-tuning of trimming +#' +#' @export +#' @return A \code{data.frame} containing keys and values +#' @seealso \code{\link{parseStrings}} +#' @examples +#' +#' parsePairs("A=3,B=4,C=5", collapse=",", sep="=") +#' parsePairs("A:3|B:4|C:5", collapse="|", sep=":") +#' +parsePairs <- function(str, collapse=",", sep="=", + colnames=c("key", "value"), + trim=TRUE,...) { + if(is.null(str)) return(NULL) + strv <- parseStrings(str, collapse=collapse, trim=trim, ...) + strl <- strsplit(strv, sep) + res <- data.frame(key=I(sapply(strl, "[", 1L)), + value=I(sapply(strl, "[", 2L))) + colnames(res) <- colnames + return(res) +} + + +#' Make a factor +#' +#' @param groups Character strings +#' @param levels Character vector, indicating strings +#' @param make.names Should names be converted to adhere to the rule of variable names in R +#' @param verbose Logical vector +#' +#' @return A factor with the specified levels. +#' @export +#' @examples +#' makeFactor(c("A", "B", "C", "C", "A"), levels=LETTERS[3:1]) +#' makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), +#' levels=c("A 1", "C 3", "B 2"), +#' make.names=TRUE) +#' makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), +#' levels=c("A 1", "C 3", "B 2"), +#' make.names=FALSE) +#' makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), +#' levels=c("A 1", "C 3", "B 2"), +#' make.names=FALSE, verbose=TRUE) +makeFactor <- function(groups, levels=NULL, make.names=TRUE, verbose=FALSE) { + if(missing(levels) || is.null(levels)) { + if(is.factor(groups)) { + levels <- levels(groups) + } else { + levels <- levels(factor(groups)) + } + } + + if(!all(groups %in% levels)) { + missing.groups <- setdiff(groups, levels) + stop("Following groups were not in levels:", paste(missing.groups, collapse=","),"\n") + } + groups <- factor(groups, levels=levels) + if(make.names) { + groups.back <- groups + levels(groups) <- make.unique(make.names(levels(groups))) + if(!identical(levels(groups.back), levels(groups))) { + isChanged <- levels(groups.back)!=levels(groups) + if(verbose) { + msg <- sprintf("%s->%s", + levels(groups.back)[isChanged], + levels(groups)[isChanged]) + warning("The following group names has been changed:\n", + paste(msg, collapse="\n")) + } + } + } + return(groups) +} + + +#' Parse a character string into factor +#' +#' @param str A character string giving groups +#' @param rlevels A character string giving levels +#' @param make.names Logical, should names be converted to adhere to the rule of variable names in R +#' @param collapse Character used in \code{relevels} to collapse different levels +#' +#' @return A factor parsed from the input string with the specified levels. +#' @export +#' @examples +#' parseFactor("A,B,C,B,A", rlevels="A,B,C") +#' +#' rgroup <- "A,B,C,D,B,C,A,D,B" +#' rlevels <- "D,A,B,C" +#' parseFactor(rgroup, rlevels) +#' +#' groups <- c("ATest", "Control", "Control", "ATest") +#' levels <- c("Control", "ATest") +#' makeFactor(groups, levels) +#' +#' # if 'groups' is a factor and 'levels' NULL or missing, its levels are respected +#' groups <- factor(c("B", "C", "A", "D"), levels=c("D","C","A","B")) +#' makeFactor(groups) +#' +#' \donttest{ +#' groups <- c("ATest", "Control", "Control", "ATest") +#' levels <- c("Control", "ATest", "Unknown") +#' makeFactor(groups, levels) +#' +#' groups <- c("ATest", "Control", "Control", "ATest", "BTest") +#' levels <- c("Control", "ATest") +#' makeFactor(groups, levels) +#' } +#' +parseFactor <- function(str, rlevels=NULL, make.names=TRUE, collapse=",") { ## CL=command line + if(is.null(str)) + stop("raw string of groups cannot be NULL") + groups <- unname(parseStrings(str, collapse=collapse)) + if(!missing(rlevels) && !is.null(rlevels)) { + grouplevels <- parseStrings(rlevels, collapse=collapse) + } else { + grouplevels <- NULL + } + makeFactor(groups, grouplevels, make.names=make.names) +} + +## parse files from command line option, which can be (1) a string vector of files, (2) a file listing input files (e.g. pointer file), (3) a directory, or (4) a zip/tar/gz file (determined by suffix). In the later two cases, file patterns can be specified +## in case of compressed files, a temp dir will be created: the user should take care of cleaning up! +isDir <- function(str) file.info(str)$isdir +## TODO: parseFiles is not checked yet! + +#' Parse files from command-line options +#' +#' Parse files from command line option, which can be (1) a string vector of files, (2) a file listing input files (e.g. pointer file), (3) a directory, or (4) a zip/tar/gz file (determined by suffix). In the later two cases, file patterns can be specified. +#' +#' @note In case of compressed files, a temp dir will be created: the user should take care of cleaning up! +#' +#' @param str A character string +#' @param sep Seperator used in the string +#' @param pattern Pattern string, if given, only files matching the pattern will be returned +#' @param recursive In cse of directory or compressed files, whether files should be found recursively +#' @param ignore.case In case of directory or compressed files, whether case should be ignored +#' +#' @return A character vector of file paths. +#' @importFrom ribiosUtils extname +#' @importFrom utils untar unzip +#' @export +parseFiles <- function(str, sep=",", pattern=NULL, recursive=TRUE, ignore.case=TRUE) { + if(file.exists(str)) { ## a compressed file or a directory + if(isDir(str)[1]) { ## directory + selfiles <- dir(str, pattern=pattern, full.names=TRUE, + recursive=recursive, ignore.case=ignore.case) + } else { + inext <- extname(str, lower.case=TRUE) + if(!is.na(inext) & inext %in% c("zip", "tar", "gz")) { ## compressed file + indir <- tempdir() + if(inext=="zip") { + unzip(zipfile=str, exdir=indir) + } else { ## assume that the file is a tar.* file + untar(tarfile=str, exdir=indir) + } + selfiles <- dir(indir, pattern=pattern, full.names=TRUE, + recursive=recursive, ignore.case=ignore.case) + } else { ## list file + selfiles <- readLines(str) + } + } + } else { ## file names concatenated by commas(,) + selfiles <- parseStrings(str) + } + return(selfiles) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/ribiosArg.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/ribiosArg.R new file mode 100644 index 0000000..2f9eba7 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/ribiosArg.R @@ -0,0 +1,9 @@ +#' @keywords internal +"_PACKAGE" + +#' ribiosIO +#' ribiosIO provides Command-line argument handling for R scripting +#' @author Jitao David Zhang +#' @useDynLib ribiosArg, .registration=TRUE, .fixes="C_" +#' @name ribiosArg +NULL diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptInit.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptInit.R new file mode 100644 index 0000000..e9332a7 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptInit.R @@ -0,0 +1,26 @@ +#' Prepare the environment for a script +#' +#' This function is called at the beginning of an Rscript, in order to +#' prepare the R environment to run in a script setting. +#' +#' @return No return value, called for side effects. +#' +#' @aliases initScript +#' @export +#' @examples +#' \donttest{ +#' scriptInit() +#' } +scriptInit <- function() { + old <- options() + on.exit(options(old)) + if(interactive()) { + setDebug() + } else { + options(error=quote({ + dump.frames(dumpto="ribios.dump", to.file=TRUE, include.GlobalEnv=TRUE) + quit(save="no", status=1L) + })) + } +} +initScript <- scriptInit diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptName.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptName.R new file mode 100644 index 0000000..a9e0342 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptName.R @@ -0,0 +1,62 @@ +#' Returns the file name of the Rscript being executed +#' +#' Get the file name of the Rscript that is currently being executed. The function is mainly called by stand-alone Rscripts. +#' +#' @details The name is determined by the \code{--file}/\code{-f} option in the command line. +#' +#' When the R session was not initiated by a Rscript (i.e. there is no \code{--file} or \code{-f} option in the command line), \code{NULL} is returned. +#' +#' Note that the function supports calling Rscript via \code{--file} or \code{-f} with \code{R}. This applies to cases where a Rscript, marked as executable, and is called from the command line. +#' +#' @return A character string containing the file name of the Rscript. +#' +#' @author Jitao David Zhang +#' @seealso \code{\link{commandArgs}} and \code{\link{getArg}} +#' +#' @export +#' @examples +#' \donttest{scriptName()} +#' +scriptName <- function() { + filename <- grep("--file=", commandArgs(), value=TRUE) + lf <- length(filename) + if(lf>1) { + warning("Multiple --file options found, only using the first") + filename <- filename[1L] + } else if (lf==1) { + restname <- strsplit(filename, "=")[[1L]][-1L] + return(paste(restname, collapse="=")) + } else if (lf==0) { ## no --file found + filename <- suppressWarnings(getArg("f", onlyArg=NULL, missingArg=NULL)) ## getArg, which is deprecated, is used here + return(filename) ## if missing: NULL, otherwise: the file name + } +} + +#' Returns the path of the Rscript being executed +#' +#' Get the normalised path of the Rscript that is currently being executed. The function is mainly called by stand-alone Rscripts. +#' +#' @details The name is determined by the \code{--file}/\code{-f} option in the command line. +#' +#' When the R session was not initiated by a Rscript (i.e. there is no \code{--file} or \code{-f} option in the command line), \code{NULL} is returned. +#' +#' Note that the function supports calling Rscript via \code{--file} or \code{-f} with \code{R}. This applies to cases where a Rscript, marked as executable, and is called from the command line. +#' +#' @return A character string containing the normalised path of the Rscript. +#' +#' @author Jitao David Zhang +#' @seealso \code{\link{scriptName}} +#' +#' @export +#' @examples +#' \donttest{scriptPath()} +#' +scriptPath <- function() { + sname <- scriptName() + if(is.null(sname)) { + return(NULL) + } else { + filename <- normalizePath(sname) + return(dirname(filename)) + } +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptSkeleton.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptSkeleton.R new file mode 100644 index 0000000..3222762 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/scriptSkeleton.R @@ -0,0 +1,39 @@ +#' Generate a Rscript with its skeleton +#' +#' @param file Output file. By default the function writes to standard output. +#' +#' @return Invisibly returns the character vector of skeleton lines. +#' Called for its side effect of writing to \code{file}. +#' @export +#' @examples +#' scriptSkeleton(file = file.path(tempdir(), "myscript.R")) + +scriptSkeleton <- function(file=stdout()) { + sentences <- c("#!/usr/bin/env Rscript", + "", + "# Initialize the script", + "suppressMessages(library(ribiosArg))", + "ribiosArg::scriptInit()", + "usage <- paste(\"Usage:\", scriptName(), \" USAGES\\nUsage Details\", sep=\"\")", + "argParse(\"log,1\", \ + \"Param1 Param2\", usage)", + "", + "# Create log", + "logfile <- argGet(\"log\", default=NULL)", + "registerLog(logfile)", + "doLog(\"%s starts\", scriptName())", + "", + "# Library loading", + "doLog(\"Library loading\")", + "libordie(ribiosBase)", + "", + "# Program logic goes here", + "", + "", + "# Quit", + "doLog(\"%s quits\", scriptName())", + "qqmsg(status=0L)", + sep="\n") + writeLines(text=sentences, con=file, sep="\n") + return(invisible(sentences)) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/zzz.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/zzz.R new file mode 100644 index 0000000..7d6552e --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/R/zzz.R @@ -0,0 +1,12 @@ +.onLoad <- function(libname, pkgname) { + if (!interactive() && !isDebugging()) { + allComm <- commandArgs(FALSE) + isScript <- any(grepl("^--file=", allComm)) || any(grepl("^-f$", allComm)) + if (isScript) { + tryCatch( + argParse(optargs = "", reqargs = "", strict = FALSE), + error = function(e) invisible(NULL) + ) + } + } +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/README.md b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/README.md new file mode 100644 index 0000000..bee023e --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/README.md @@ -0,0 +1,19 @@ +*ribiosArg*: Handling command-line arguments of stand-alone R programs +=== + +![R-CMD-check badge](https://github.com/bedapub/ribiosArg/workflows/R-CMD-check/badge.svg) + +## What is *ribiosArg*? + +*ribiosUtils* is a R package in the *ribios* suite that handles command-line arguments of stand-alone R programs. It is used to build R programs that run via command-line. + +It is distributed under the GPL-3 license. + +## Installation + +Run following commands in the R console. + +```{R} +library(devtools) +devtools::install_github("bedapub/ribiosArg") +``` diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/minimal.Rscript b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/minimal.Rscript new file mode 100755 index 0000000..b0b945b --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/minimal.Rscript @@ -0,0 +1,69 @@ +#!/usr/bin/env Rscript + +# A minimalistic Rscript demonstrating the usage of the ribiosArg package to parse command-line parameters of Rscript +# Released under the GPL-3 license by Jitao David Zhang, + +suppressMessages(library(ribiosUtils)) +suppressMessages(library(ribiosArg)) +scriptInit() + +usage <- paste("Print the results of two numbers applied to an operation, with optional output of the equation\n", + "Usage:", scriptName(), "-num1 NUM -num2 NUM -outfile FILE [-operation OPT] [-printEq] [-log LOG]\n", + "Mandatory options:\n", + " -num1: A number\n", + " -num2: Another number\n", + " -outfile: Output file where the results will be written to. Use '-' to write the results on the standard output.\n", + "Optional options:\n", + " -printEq: If set, the equation is printed\n", + " -operation: Operation, supported values include 'add', 'subtract', 'divide', and 'multiply'. Default: 'add'\n", + " -log: File name to which the log of the program will be written. use '-' to write the log on the standard output.\n", sep="") + +argParse(optargs="printEq operation,1 log,1", + reqargs="num1 num2 outfile", usage=usage) + +##----------------------------------------## +## Program starts +##----------------------------------------## +logfile <- argGet("log", default=NULL) +registerLog(logfile) +doLog("%s starts", scriptName()) + +##----------------------------------------## +## Logic +##----------------------------------------## +outfile <- argGet("outfile") +if(outfile == "-") { + outfile <- stdout() +} +num1 <- parseNumVec(argGet("num1"), expLen=1L) +num2 <- parseNumVec(argGet("num2"), expLen=1L) + +operation <- argGet("operation", choices=c("add", "subtract", "divide", "multiply"), default="add") +printEq <- argPresent("printEq") + +doLog("Doing operation") +if(operation=="add") { + res <- num1 + num2 +} else if (operation=="subtract") { + res <- num1 - num2 +} else if (operation=="multiply") { + res <- num1 * num2 +} else if (operation=="divide") { + res <- num1 * num2 +} + +if(printEq) { + opSym <- c("add"="+", "subtract"="-", "multiply"="*", "divide"="/")[operation] + str <- sprintf("%g %s %g = %g", num1, opSym, num2, res) +} else { + str <- sprintf("%g", res) +} +doLog("Writing output") +writeLines(str, outfile) + +##--------------------## +## Quit +##--------------------## +doLog("Program quitting") +qqmsg(status=0) + diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse-notstrict.Rscript b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse-notstrict.Rscript new file mode 100644 index 0000000..aecea3b --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse-notstrict.Rscript @@ -0,0 +1,21 @@ +#!/bin/bash /SOFT/bi/apps/R/bdeRscript + +library(ribiosArg) +usage <- sprintf("%s -infile INFILE -outfile OUTFILE [-a Low Up] [-b] [-c Mid] [-d]\ + -infile: input file\ + -outfile: output file\ + -a LOW UP: thresholds\ + -b: Add b\ + -c: Mid point\ + -d: Multiply by d", scriptName()) + +res <- argParse(optargs="b a,2 c,1 d", reqargs="infile outfile", usage=usage, strict=FALSE) +cat("infile:", argGet("infile"),"\n") +cat("outfile:", argGet("outfile"),"\n") +cat("c:", argGet("c"), "\n") +cat("a[1]:", argGetPos("a",1), "\n") +cat("a[2]:", argGetPos("a",2), "\n") +cat("b:", argPresent("b"), "\n") +cat("d:", argPresent("d"), "\n") +cat("d:", argGet("d"), "\n") +cat("extra parameters:", paste(res, collapse=" "), "\n") diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse.Rscript b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse.Rscript new file mode 100755 index 0000000..0c1ff70 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/Rscript/test-argParse.Rscript @@ -0,0 +1,28 @@ +#!/usr/bin/env Rscript + +suppressMessages(library(ribiosUtils)) +suppressMessages(library(ribiosArg)) +scriptInit() + +usage <- sprintf("%s -infile INFILE -outfile OUTFILE [-a Low Up] [-b] [-c Mid] [-d] [-e OPT]\ + Mandatory:\ + -infile: input file\ + -outfile: output file\ + Optional:\ + -a LOW UP: Two parameters expected\ + -b: Flag variable, no parameter expected\ + -c: One parameter expected\ + -d: Flag variable, no parameter expected\ + -e: accepts only following values: a, b, c", scriptName()) + +argParse(optargs="b a,2 c,1 d e", reqargs="infile outfile", usage=usage, strict=TRUE) +cat("infile:", argGet("infile"),"\n") +cat("outfile:", argGet("outfile"),"\n") +cat("c:", argGet("c"), "\n") +cat("a[1]:", argGetPos("a",1), "\n") +cat("a[2]:", argGetPos("a",2), "\n") +cat("b:", argPresent("b"), "\n") +cat("d is present:", argPresent("d"), "\n") +cat("e:", argGet("e"), "\n") +cat("e:", argGet("e", choices=c("a", "b", "c")), "\n") + diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/include/ribios_arg.h b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/include/ribios_arg.h new file mode 100644 index 0000000..329adb3 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/inst/include/ribios_arg.h @@ -0,0 +1,33 @@ +#ifndef RIBIOS_ARG_H +#define RIBIOS_ARG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include +#include +#include + +#define CALLMETHOD_DEF(fun, numArgs) {#fun, (DL_FUNC) &fun, numArgs} + +// functions from ribiosUtils +extern void(*usage)(char*, ...); +extern void(*strReplace)(char**, char*); +extern int(*arg_init)(int, char*[], char*, char*, void (*usagef)(int)); +extern int(*arg_isInit)(void); +extern char*(*arg_getPos)(char*, int); +extern int(*arg_present)(char*); +extern void*(*hlr_callocs)(size_t, size_t); + +extern SEXP rarg_isInit(); +extern SEXP rarg_parse(SEXP, SEXP, SEXP, SEXP, SEXP); +extern SEXP rarg_get(SEXP); +extern SEXP rarg_getPos(SEXP, SEXP); +extern SEXP rarg_present(SEXP); + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGet.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGet.Rd new file mode 100644 index 0000000..87ff877 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGet.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/argparse.R +\name{argGet} +\alias{argGet} +\title{Parse an argument} +\usage{ +argGet(opt, default = NULL, choices = NULL) +} +\arguments{ +\item{opt}{name of the argument to be parsed} + +\item{default}{default values to be returned if the argument is not provided} + +\item{choices}{a character vector of accepted values; if a string outside the vector is provided, the function will stop and print error message} +} +\value{ +A character string representing the value of the argument +} +\description{ +Get the value of an named argument +} +\details{ +The parsing is performed at C-level. It is an abbreiviation of argGetPos(opt, ind=1, default=NULL, choices=NULL) +} +\examples{ +\donttest{argGet("infile")} + +} +\seealso{ +\code{\link{argParse}}, \code{\link{argGetPos}}, and \code{\link{argPresent}} +} +\author{ +Jitao David Zhang +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGetPos.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGetPos.Rd new file mode 100644 index 0000000..be323bb --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argGetPos.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/argparse.R +\name{argGetPos} +\alias{argGetPos} +\title{Parse an argument with the given position} +\usage{ +argGetPos(opt, ind = 1L, default = NULL, choices = NULL) +} +\arguments{ +\item{opt}{name of the argument to be parsed} + +\item{ind}{index of the argument to be parsed, starting from 1.} + +\item{default}{default values to be returned if the argument is not provided} + +\item{choices}{a character vector of accepted values; if a string outside the vector is provided, the function will stop and print error message} +} +\value{ +A character string representing the value of the argument +} +\description{ +Get the value of an named argument with the given position +} +\details{ +The parsing is performed at C-level. If the argument accepts only one value, users can also call argGet(opt, default=NULL, choices=NULL) +} +\examples{ +\donttest{argGetPos("thresholds", ind=2)} + +} +\seealso{ +\code{\link{argParse}}, \code{\link{argGet}}, and \code{\link{argPresent}} +} +\author{ +Jitao David Zhang +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argIsInit.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argIsInit.Rd new file mode 100644 index 0000000..ad57298 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argIsInit.Rd @@ -0,0 +1,14 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/argparse.R +\name{argIsInit} +\alias{argIsInit} +\title{Check whether the argument parser has been initialized} +\usage{ +argIsInit() +} +\value{ +Logical, \code{TRUE} if \code{argParse} has been called, \code{FALSE} otherwise. +} +\description{ +Check whether the argument parser has been initialized +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argParse.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argParse.Rd new file mode 100644 index 0000000..991b965 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/argParse.Rd @@ -0,0 +1,62 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/argparse.R +\name{argParse} +\alias{argParse} +\alias{argPresent} +\title{Parser of command-line parameters in BIOS style} +\usage{ +argParse(optargs, reqargs, usage = paste(scriptName(), "-h"), strict = TRUE) + +argPresent(opt) +} +\arguments{ +\item{optargs}{String describing optional arguments. Syntax: \code{[,paramcnt1] [,paramcnt2]\dots}. Example: \dQuote{verbose outfile,1} means the command line has the syntax \code{prog [-verbose] [outfile name]}. It can be an empty string to express \dQuote{no options}. The value for \code{paramcnt} is 0.} + +\item{reqargs}{String describining required arguments. Syntax: \code{ \dots}. Example: \dQuote{infile outfile} means the command line has the syntax \code{prog [-infile ]infile [-outfile ]coutfile}. Even if it is empty, it is checked that at least one non-optional value is given.} + +\item{usage}{A character string to be printed if the command-line option parsing fails} + +\item{strict}{Logical, are extra un-prefixed parameters allowed? If set to \code{TRUE}, the un-prefixed parameters (which must be at the end of the command line) will be returned as a character vector.} + +\item{opt}{Character string, option name} +} +\value{ +\code{argParse} is used for the side effects. If \code{strict} is set to +\code{TRUE}, an invisible \code{NULL} is returned; otherwise, extra +un-prefixed parameters are returned as an invisible character vector + +\code{argGet} and \code{argGetPos} returns a character +string. \code{argPresent} returns a boolean value. + +In case of any error (wrong syntax, or not-existing option) the R +session quits while printing the error message. +} +\description{ +Parser of command-line parameters in BIOS style + +Test whether the given option is present in the command line or not +} +\details{ +\code{argParse} must be called before \code{argGet},\code{argGetPos} + , \code{argPresent}, or \code{argGetDefault}. It checks whether the command line syntax agrees + with the specification of \code{optargs} and \code{reqargs}. If not, + the \code{usage} message is printed and the program exists. + + \code{argPresent} returns a boolean value indicating whether the option is present or not. + + If the syntax was found correct, \code{argGetPos} can be called to + fetch the \code{ind}th value of the option \code{opt} (indexing from 1). For instance, + if the following option \code{-ranges 3 5} is defined, + argGetPos(\dQuote{range}, 2) returns \code{5}. \code{argGet} is + a shortcut to fetch the first element. If the opt is missing, the + \code{default} value will be returned. +} +\examples{ +\donttest{ +argParse("verbose threshold,2", "infile outfile", + usage="prog [-infile ]infile [-outfile ]outfile [-verbose] [-threshold MIN MAX]") +argIsInit() +argPresent("verbose") +} + +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/existArg.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/existArg.Rd new file mode 100644 index 0000000..b522179 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/existArg.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/existArg.R +\name{existArg} +\alias{existArg} +\title{Test if named arguments exists} +\usage{ +existArg(args) +} +\arguments{ +\item{args}{Argument names, without leading minus sign} +} +\value{ +A vector of logicals, indicating whether the arguments exist +} +\description{ +Test if named arguments exists +} +\details{ +Options are those arguments with a leading minus sign +(e.g. "-opt"). This function tells whether queried options exist in +the argument list. +} +\examples{ +comm <- paste(c("Rscript --vanilla -e", "'", "library(ribiosArg);", + "existArg(c(\"opt\", \"opt2\", \"opt3\"))", "'", + "-opt abc -opt3"), collapse=" ") +system(comm) +} +\seealso{ +\code{\link{getArg}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/getArg.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/getArg.Rd new file mode 100644 index 0000000..b152f8f --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/getArg.Rd @@ -0,0 +1,33 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/getArg.R +\name{getArg} +\alias{getArg} +\title{An R-implementation of getting named aguments} +\usage{ +getArg(args, onlyArg = FALSE, missingArg = FALSE) +} +\arguments{ +\item{args}{Character strings, named arguments} + +\item{onlyArg}{Any type, What value should be returned if only the option is available and no value has been provided} + +\item{missingArg}{Any type, What value should be returned if the option is not available} +} +\value{ +A list when more than one option were queried; or a vector if only one option was queried. +} +\description{ +This function is out-dated. Please use \code{argparse} instead. +} +\details{ +Options are those arguments with a leading minus sign. They can +have one or more values following them, which will be taken as the value +of the option. If no such values are availble, user could decide how to +interpret the option by setting the \code{onlyArg} parameter. Similarly, +missing options can be handled by \code{missingArg} + +From version 1.0.3 \code{onlyArg} and \code{missingArg} accepts \code{NULL} as inputs. +} +\seealso{ +\code{\link{existArg}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isDebugging.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isDebugging.Rd new file mode 100644 index 0000000..1394134 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isDebugging.Rd @@ -0,0 +1,24 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/debugging.R +\name{isDebugging} +\alias{isDebugging} +\title{Test whether the environment is set for debugging} +\usage{ +isDebugging() +} +\value{ +A logical value +} +\description{ +Test whether the environment is set for debugging +} +\examples{ +isDebugging() +unsetDebug() +isDebugging() +setDebug() + +} +\seealso{ +\code{\link{setDebug}} and \code{\link{unsetDebug}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isIntDebugging.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isIntDebugging.Rd new file mode 100644 index 0000000..f7f2081 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/isIntDebugging.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/debugging.R +\name{isIntDebugging} +\alias{isIntDebugging} +\title{Test whether the environment is set for debugging, or it's an interactive session} +\usage{ +isIntDebugging() +} +\value{ +A logical value +} +\description{ +Test whether the environment is set for debugging, or it's an interactive session +} +\seealso{ +\code{\link{isDebugging}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/makeFactor.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/makeFactor.Rd new file mode 100644 index 0000000..4e246e1 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/makeFactor.Rd @@ -0,0 +1,35 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parseFuncs.R +\name{makeFactor} +\alias{makeFactor} +\title{Make a factor} +\usage{ +makeFactor(groups, levels = NULL, make.names = TRUE, verbose = FALSE) +} +\arguments{ +\item{groups}{Character strings} + +\item{levels}{Character vector, indicating strings} + +\item{make.names}{Should names be converted to adhere to the rule of variable names in R} + +\item{verbose}{Logical vector} +} +\value{ +A factor with the specified levels. +} +\description{ +Make a factor +} +\examples{ +makeFactor(c("A", "B", "C", "C", "A"), levels=LETTERS[3:1]) +makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), + levels=c("A 1", "C 3", "B 2"), + make.names=TRUE) +makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), + levels=c("A 1", "C 3", "B 2"), + make.names=FALSE) +makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), + levels=c("A 1", "C 3", "B 2"), + make.names=FALSE, verbose=TRUE) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFactor.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFactor.Rd new file mode 100644 index 0000000..5beea99 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFactor.Rd @@ -0,0 +1,49 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parseFuncs.R +\name{parseFactor} +\alias{parseFactor} +\title{Parse a character string into factor} +\usage{ +parseFactor(str, rlevels = NULL, make.names = TRUE, collapse = ",") +} +\arguments{ +\item{str}{A character string giving groups} + +\item{rlevels}{A character string giving levels} + +\item{make.names}{Logical, should names be converted to adhere to the rule of variable names in R} + +\item{collapse}{Character used in \code{relevels} to collapse different levels} +} +\value{ +A factor parsed from the input string with the specified levels. +} +\description{ +Parse a character string into factor +} +\examples{ +parseFactor("A,B,C,B,A", rlevels="A,B,C") + +rgroup <- "A,B,C,D,B,C,A,D,B" +rlevels <- "D,A,B,C" +parseFactor(rgroup, rlevels) + +groups <- c("ATest", "Control", "Control", "ATest") +levels <- c("Control", "ATest") +makeFactor(groups, levels) + +# if 'groups' is a factor and 'levels' NULL or missing, its levels are respected +groups <- factor(c("B", "C", "A", "D"), levels=c("D","C","A","B")) +makeFactor(groups) + +\donttest{ +groups <- c("ATest", "Control", "Control", "ATest") +levels <- c("Control", "ATest", "Unknown") +makeFactor(groups, levels) + +groups <- c("ATest", "Control", "Control", "ATest", "BTest") +levels <- c("Control", "ATest") +makeFactor(groups, levels) +} + +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFiles.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFiles.Rd new file mode 100644 index 0000000..85a32c5 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseFiles.Rd @@ -0,0 +1,34 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parseFuncs.R +\name{parseFiles} +\alias{parseFiles} +\title{Parse files from command-line options} +\usage{ +parseFiles( + str, + sep = ",", + pattern = NULL, + recursive = TRUE, + ignore.case = TRUE +) +} +\arguments{ +\item{str}{A character string} + +\item{sep}{Seperator used in the string} + +\item{pattern}{Pattern string, if given, only files matching the pattern will be returned} + +\item{recursive}{In cse of directory or compressed files, whether files should be found recursively} + +\item{ignore.case}{In case of directory or compressed files, whether case should be ignored} +} +\value{ +A character vector of file paths. +} +\description{ +Parse files from command line option, which can be (1) a string vector of files, (2) a file listing input files (e.g. pointer file), (3) a directory, or (4) a zip/tar/gz file (determined by suffix). In the later two cases, file patterns can be specified. +} +\note{ +In case of compressed files, a temp dir will be created: the user should take care of cleaning up! +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseNumVec.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseNumVec.Rd new file mode 100644 index 0000000..129ec9a --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseNumVec.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parseFuncs.R +\name{parseNumVec} +\alias{parseNumVec} +\title{Parse a character string into a numveric vector} +\usage{ +parseNumVec(str, expLen = 2, failVal = c(5, 5), sep = ",") +} +\arguments{ +\item{str}{A character string} + +\item{expLen}{Integer or \code{NULL}, Expected length of the numeric vector. When set to NULL, the numeric vector can be of variable length.} + +\item{failVal}{If the parsing failed (for example length not correct, or non-numeric values were provided, this value will be returned} + +\item{sep}{Separator in the character string, default ","} +} +\value{ +A numeric vector of the parsed values, or \code{failVal} if parsing fails. +} +\description{ +Numeric vectors can be given as arguments in two ways: (1) separated by +blanks or (2) separated by other common separators, such as comma +(,). This function parses a string, or a string vector into a numeric +vector of expected length. In addition it is failure safe: user can +specify the return value in case the parsing was not successful, +} +\details{ +The input value mostly comes from return values of the \code{\link{argGet}} function. +} +\examples{ +parseNumVec("3,7,9", expLen=3) +} +\seealso{ +\code{\link{argGet}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parsePairs.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parsePairs.Rd new file mode 100644 index 0000000..e591877 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parsePairs.Rd @@ -0,0 +1,48 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parseFuncs.R +\name{parsePairs} +\alias{parsePairs} +\title{Parse key-value pairs from a character string} +\usage{ +parsePairs( + str, + collapse = ",", + sep = "=", + colnames = c("key", "value"), + trim = TRUE, + ... +) +} +\arguments{ +\item{str}{Character string} + +\item{collapse}{Collapse character used in the string} + +\item{sep}{Seperator used in the string} + +\item{colnames}{Column names of the returned \code{data.frame}} + +\item{trim}{Logical, whether additional spaces should be trimmed} + +\item{...}{Further parameters passed to \code{\link[ribiosUtils]{trim}} for fine-tuning of trimming} +} +\value{ +A \code{data.frame} containing keys and values +} +\description{ +The function parses parameters in the form of + \code{KEY1=VAL1,KEY2=VAL2,KEY3=VAL3} into \code{data.frame}. +} +\details{ +If input string is \code{NULL}, the function returns \code{NULL}. This +can be useful in case the parameter is optional and not specified. +} +\examples{ + +parsePairs("A=3,B=4,C=5", collapse=",", sep="=") +parsePairs("A:3|B:4|C:5", collapse="|", sep=":") + +} +\seealso{ +\code{\link{parseStrings}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseStrings.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseStrings.Rd new file mode 100644 index 0000000..7bb0b8a --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/parseStrings.Rd @@ -0,0 +1,46 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/parseFuncs.R +\name{parseStrings} +\alias{parseStrings} +\title{Parse a character string into string vectors} +\usage{ +parseStrings(str, collapse = ",", trim = TRUE, ...) +} +\arguments{ +\item{str}{A character string to be parsed} + +\item{collapse}{Character(s) used in the character string to concatenate strings} + +\item{trim}{Logical, whether additional spaces should be trimmed} + +\item{...}{Further parameters passed to \code{\link[ribiosUtils]{trim}} for fine-tuning of trimming} +} +\value{ +A vector of character strings +} +\description{ +This function parses collapsed multiple options into a vector of +character strings. Each option is optionally trimmed of leading and tailing empty +spaces given by \code{trim}. See examples. +} +\details{ +In case of multiple separators, they can be given by concatenating + with piple signs, e.g. \code{,|\\t}. + If input string is \code{NULL}, the function returns \code{NULL}. This + can be useful in case the parameter is optional and not specified. +} +\examples{ +parseStrings("veni, vidi, vici") +parseStrings("veni, vidi, vici", trim=FALSE) +parseStrings("I came, I saw, I conquered") + +# options are trimmed +parseStrings("a,b,\tc,d\n") +# it works also with only one option +parseStrings("a") +# more than one separators +parseStrings("a,b,c;d", collapse=",|;") +} +\seealso{ +\code{\link{strsplit}}, \code{\link[ribiosUtils]{trim}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg-package.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg-package.Rd new file mode 100644 index 0000000..238c014 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg-package.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ribiosArg.R +\docType{package} +\name{ribiosArg-package} +\alias{ribiosArg-package} +\title{ribiosArg: Argument Handling for Command-Line, Stand-Alone R Scripts} +\description{ +Provides functions to handle command-line arguments for R scripting. It enables building stand-alone R programs that accept and parse command-line options in 'BIOS' style. Zhang (2025) \url{https://github.com/bedapub/ribiosArg}. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://github.com/bedapub/ribiosArg} + \item Report bugs at \url{https://github.com/bedapub/ribiosArg/issues} +} + +} +\author{ +\strong{Maintainer}: Jitao David Zhang \email{jitao_david.zhang@roche.com} (\href{https://orcid.org/0000-0002-3085-0909}{ORCID}) [contributor] + +} +\keyword{internal} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg.Rd new file mode 100644 index 0000000..d7c1f2f --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/ribiosArg.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ribiosArg.R +\name{ribiosArg} +\alias{ribiosArg} +\title{ribiosIO +ribiosIO provides Command-line argument handling for R scripting} +\description{ +ribiosIO +ribiosIO provides Command-line argument handling for R scripting +} +\author{ +Jitao David Zhang +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptInit.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptInit.Rd new file mode 100644 index 0000000..7ff44cb --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptInit.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scriptInit.R +\name{scriptInit} +\alias{scriptInit} +\alias{initScript} +\title{Prepare the environment for a script} +\usage{ +scriptInit() +} +\value{ +No return value, called for side effects. +} +\description{ +This function is called at the beginning of an Rscript, in order to +prepare the R environment to run in a script setting. +} +\examples{ +\donttest{ + scriptInit() +} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptName.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptName.Rd new file mode 100644 index 0000000..51d7afe --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptName.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scriptName.R +\name{scriptName} +\alias{scriptName} +\title{Returns the file name of the Rscript being executed} +\usage{ +scriptName() +} +\value{ +A character string containing the file name of the Rscript. +} +\description{ +Get the file name of the Rscript that is currently being executed. The function is mainly called by stand-alone Rscripts. +} +\details{ +The name is determined by the \code{--file}/\code{-f} option in the command line. + +When the R session was not initiated by a Rscript (i.e. there is no \code{--file} or \code{-f} option in the command line), \code{NULL} is returned. + +Note that the function supports calling Rscript via \code{--file} or \code{-f} with \code{R}. This applies to cases where a Rscript, marked as executable, and is called from the command line. +} +\examples{ +\donttest{scriptName()} + +} +\seealso{ +\code{\link{commandArgs}} and \code{\link{getArg}} +} +\author{ +Jitao David Zhang +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptPath.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptPath.Rd new file mode 100644 index 0000000..7303e39 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptPath.Rd @@ -0,0 +1,31 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scriptName.R +\name{scriptPath} +\alias{scriptPath} +\title{Returns the path of the Rscript being executed} +\usage{ +scriptPath() +} +\value{ +A character string containing the normalised path of the Rscript. +} +\description{ +Get the normalised path of the Rscript that is currently being executed. The function is mainly called by stand-alone Rscripts. +} +\details{ +The name is determined by the \code{--file}/\code{-f} option in the command line. + +When the R session was not initiated by a Rscript (i.e. there is no \code{--file} or \code{-f} option in the command line), \code{NULL} is returned. + +Note that the function supports calling Rscript via \code{--file} or \code{-f} with \code{R}. This applies to cases where a Rscript, marked as executable, and is called from the command line. +} +\examples{ +\donttest{scriptPath()} + +} +\seealso{ +\code{\link{scriptName}} +} +\author{ +Jitao David Zhang +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptSkeleton.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptSkeleton.Rd new file mode 100644 index 0000000..382457b --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/scriptSkeleton.Rd @@ -0,0 +1,21 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/scriptSkeleton.R +\name{scriptSkeleton} +\alias{scriptSkeleton} +\title{Generate a Rscript with its skeleton} +\usage{ +scriptSkeleton(file = stdout()) +} +\arguments{ +\item{file}{Output file. By default the function writes to standard output.} +} +\value{ +Invisibly returns the character vector of skeleton lines. + Called for its side effect of writing to \code{file}. +} +\description{ +Generate a Rscript with its skeleton +} +\examples{ +scriptSkeleton(file = file.path(tempdir(), "myscript.R")) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/setDebug.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/setDebug.Rd new file mode 100644 index 0000000..5872d2e --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/setDebug.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/debugging.R +\name{setDebug} +\alias{setDebug} +\title{Set the enrivonment for debugging} +\usage{ +setDebug() +} +\value{ +A logical value, whether the setting was susccessful or not +} +\description{ +Set the enrivonment for debugging +} +\seealso{ +\code{\link{isDebugging}} and \code{\link{unsetDebug}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/unsetDebug.Rd b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/unsetDebug.Rd new file mode 100644 index 0000000..78b5a9f --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/man/unsetDebug.Rd @@ -0,0 +1,17 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/debugging.R +\name{unsetDebug} +\alias{unsetDebug} +\title{Remove the debugging flag of the the enrivonment} +\usage{ +unsetDebug() +} +\value{ +A logical value, whether the removal was successful or not +} +\description{ +Remove the debugging flag of the the enrivonment +} +\seealso{ +\code{\link{isDebugging}} and \code{\link{setDebug}} +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/Makevars b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/Makevars new file mode 100644 index 0000000..50c1683 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/Makevars @@ -0,0 +1 @@ +PKG_CFLAGS=-I../inst/include diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/argparse.c b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/argparse.c new file mode 100644 index 0000000..8803515 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/src/argparse.c @@ -0,0 +1,86 @@ +#include + +#include "argparse.h" +#include "ribios_arg.h" + +// The following macros are copied from ribiosUtils +int hlr_allocCnt=0; +#define arg_get(name) arg_getPos(name,1) +#define hlr_calloc(nelem,elsize) (++hlr_allocCnt,hlr_callocs(nelem,elsize)) +#define hlr_free(x) ((x) ? free(x),--hlr_allocCnt,x=0,1 : 0) + +// The following macros are defined for ribiosUtils +#define rstr2c(x) strdup(CHAR(STRING_ELT((x),0))) +#define rstrVec2c(x,i) strdup(CHAR(STRING_ELT((x),(i)))) +#define checkInit() if(!arg_isInit()) { \ + REprintf("Error: arg_init()/arg_try() has not been called\n"); \ + return(R_NilValue); \ + } + + +char* msg=""; + +// @importFrom ribiosUtils usage +void usagef (int level) { + usage(msg); + level++; // no logic: just to avoid the warning that level is not used +} + +// @importFrom ribiosUtils strReplace hlr_calloc arg_init +SEXP rarg_parse(SEXP argc, SEXP argv, SEXP optargs, SEXP reqargs, SEXP usage) { + int i; + int rargc; + static char **rargv=NULL; + static char *oargs=NULL; + static char *rargs=NULL; + + rargc=asInteger(argc); + if(!rargv) + rargv= (char **)hlr_calloc (rargc,sizeof (char *)); + + for(i=0;i +#include +#include "ribios_arg.h" + +static const R_CallMethodDef callMethods[] = { + CALLMETHOD_DEF(rarg_parse, 5), + CALLMETHOD_DEF(rarg_isInit, 0), + CALLMETHOD_DEF(rarg_get, 1), + CALLMETHOD_DEF(rarg_getPos, 2), + CALLMETHOD_DEF(rarg_present, 1), + {NULL, NULL, 0} +}; + +// define imports from ribiosUtils +void(*usage)(char*, ...); +void(*strReplace)(char**, char*); +int(*arg_init)(int, char*[], char*, char*, void (*usagef)(int)); +int(*arg_isInit)(void); +char*(*arg_getPos)(char*, int); +int(*arg_present)(char*); +void*(*hlr_callocs)(size_t, size_t); + +void attribute_visible R_init_ribiosArg(DllInfo *info) { + R_registerRoutines(info, NULL, callMethods, NULL, NULL); + R_useDynamicSymbols(info, FALSE); + R_forceSymbols(info, TRUE); + + // C functions implemented in ribiosUtils + usage = (void(*)(char*, ...)) R_GetCCallable("ribiosUtils", "usage"); + strReplace = (void(*)(char**, char*)) R_GetCCallable("ribiosUtils", "strReplace"); + arg_init = (int(*)(int, char*[], char*, char*, void (*usagef)(int))) R_GetCCallable("ribiosUtils", "arg_init"); + arg_isInit = (int(*)(void)) R_GetCCallable("ribiosUtils", "arg_isInit"); + arg_getPos = (char*(*)(char*, int)) R_GetCCallable("ribiosUtils", "arg_getPos"); + arg_present = (int(*)(char*)) R_GetCCallable("ribiosUtils", "arg_present"); + hlr_callocs = (void*(*)(size_t, size_t)) R_GetCCallable("ribiosUtils", "hlr_callocs"); +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argParse.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argParse.R new file mode 100644 index 0000000..06fbb43 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argParse.R @@ -0,0 +1,15 @@ +library(ribiosArg) + +rexe <- file.path(dirname(dirname(commandArgs()[1])), + "R") +rscript <- system.file("Rscript/test-argParse.Rscript", package="ribiosArg") +comm1 <- sprintf("%s -infile blablabla -outfile bla2 -a 34 48 -c 45 -b -e a", rscript) +comm2 <- sprintf("%s -f %s -infile blablabla -outfile bla2 -a 34 48 -c 45 -b -e b", rexe, rscript) +system(comm1) +system(comm2) + +ns.rscript <- system.file("Rscript/test-argParse-notstrict.Rscript", package="ribiosArg") +comm1 <- sprintf("%s -infile blablabla -outfile bla2 -a 34 48 -c 45 -b -e c", rscript) +comm2 <- sprintf("%s -f %s -infile blablabla -outfile bla2 -a 34 48 -c 45 -b f1 f2 f3 -e b", rexe, rscript) +system(comm1) +system(comm2) diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argPresent_uninit.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argPresent_uninit.R new file mode 100644 index 0000000..b044a48 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_argPresent_uninit.R @@ -0,0 +1,13 @@ +library(ribiosArg) + +# Ensure argPresent returns FALSE (not error) without argParse +res <- argPresent("nonexistent") +stopifnot(identical(res, FALSE)) + +# Ensure argGet returns default without argParse +res2 <- argGet("nonexistent", default = "mydefault") +stopifnot(identical(res2, "mydefault")) + +# argGetPos returns default +res3 <- argGetPos("nonexistent", ind = 1L, default = 42) +stopifnot(identical(res3, 42)) diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_getArg.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_getArg.R new file mode 100644 index 0000000..d2ae1ec --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_getArg.R @@ -0,0 +1,52 @@ +## test getArg +library(ribiosArg) + +rscript <- file.path(dirname(dirname(commandArgs()[1])), + "Rscript") + +## useful for cases where there is a WARNING message (e.g. "WARNING: ignoring environment value of R_HOME") +identicalWoWarning <- function(x,y) { + x <- x[!grepl("^WARNING",x)] + identical(x,y) +} +if(file.exists(rscript)) { + comm.format <- paste(rscript, + "-e \"", + "library(ribiosArg);", + "getArg(\\\"%s\\\", onlyArg=%s, missingArg=%s);", + "quit(status=0, save=\\\"no\\\")", + "\"", + "-infile a.file b.file -outfile o.file o2.file -value 2,3 -value2 3 4 6 NA -hey -hallo", + collapse=" ") + comm <- sprintf(comm.format, "infile", "NA", "NA") + comm.out <- system(comm, intern=TRUE) + stopifnot(identicalWoWarning(comm.out, "[1] \"a.file\" \"b.file\"")); + + comm2 <- sprintf(comm.format, "outfile", "NULL", "NULL") + comm2.out <- system(comm2, intern=TRUE) + stopifnot(identicalWoWarning(comm2.out, "[1] \"o.file\" \"o2.file\"")) + + comm3 <- sprintf(comm.format, "value", "NULL", "NA") + comm3.out <- system(comm3, intern=TRUE) + stopifnot(identicalWoWarning(comm3.out, "[1] \"2,3\"")) + + comm4 <- sprintf(comm.format, "value2", "\\\"0\\\"","\\\"0\\\"") + comm4.out <- system(comm4, intern=TRUE) + stopifnot(identicalWoWarning(comm4.out, "[1] \"3\" \"4\" \"6\" \"NA\"")) + + comm5 <- sprintf(comm.format, "hallo", "\\\"1887\\\"", "NULL") + comm5.out <- system(comm5, intern=TRUE) + stopifnot(identicalWoWarning(comm5.out, "[1] \"1887\"")) + + comm6 <- sprintf(comm.format, "hello", "\\\"Impossible\\\"", "NA") + comm6.out <- system(comm6, intern=TRUE) + stopifnot(identicalWoWarning(comm6.out, "[1] NA")) + + comm6a <- sprintf(comm.format, "hello", "\\\"Impossible\\\"", "\\\"Sure\\\"") + comm6a.out <- system(comm6a, intern=TRUE) + stopifnot(identicalWoWarning(comm6a.out, "[1] \"Sure\"")) + + comm6b <- sprintf(comm.format, "hello", "\\\"Impossible\\\"", "NULL") + comm6b.out <- system(comm6b, intern=TRUE) + stopifnot(identicalWoWarning(comm6b.out, "NULL")) +} diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_parseNumVec.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_parseNumVec.R new file mode 100644 index 0000000..140d13d --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_parseNumVec.R @@ -0,0 +1,19 @@ +library(ribiosArg) + +myval <- parseNumVec(c("2", "3", "5.5"), expLen=3, failVal=c(3,4,5)) +stopifnot(identical(myval, c(2, 3,5.5))) + +myval2 <- parseNumVec(c("2,3,5.5"), expLen=3, failVal=c(3,4,5)) +stopifnot(identical(myval, c(2, 3,5.5))) + +myval3 <- parseNumVec(c("2,3,", "4"), expLen=3, failVal=c(3,4,5)) +stopifnot(identical(myval3, c(2, 3,4))) + +myval4 <- parseNumVec(c("2,3,", "5.5"), expLen=4, failVal=c(3,4,5)) +stopifnot(identical(myval4, c(3,4,5))) + +myval5 <- parseNumVec(c("2", "3", "5.5", "7"), expLen=NULL, failVal=c(3,4,5)) +stopifnot(identical(myval5, c(2,3,5.5,7))) + +myval6 <- parseNumVec(c("2", "3", "5.5", "HSV"), expLen=4, failVal=c(3,4,5,5)) +stopifnot(identical(myval6, c(3,4,5,5))) diff --git a/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_scriptName.R b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_scriptName.R new file mode 100755 index 0000000..aa31637 --- /dev/null +++ b/ribiosArg.Rcheck/00_pkg_src/ribiosArg/tests/test_scriptName.R @@ -0,0 +1,8 @@ +#!/bin/tcsh /SOFT/bi/apps/R/bdeRscript + +## test getArg +library(ribiosArg) +print(scriptName()) +print(commandArgs()) +stopifnot(identical("test_scriptName.R", scriptName())) + diff --git a/ribiosArg.Rcheck/00check.log b/ribiosArg.Rcheck/00check.log new file mode 100644 index 0000000..f3613f0 --- /dev/null +++ b/ribiosArg.Rcheck/00check.log @@ -0,0 +1,69 @@ +* using log directory ‘/home/david/projects/ribios/ribiosArg/ribiosArg.Rcheck’ +* using R version 4.5.2 (2025-10-31) +* using platform: x86_64-pc-linux-gnu +* R was compiled by + gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0 + GNU Fortran (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0 +* running under: Linux Mint 21.2 +* using session charset: UTF-8 +* checking for file ‘ribiosArg/DESCRIPTION’ ... OK +* checking extension type ... Package +* this is package ‘ribiosArg’ version ‘1.5.0’ +* package encoding: UTF-8 +* checking package namespace information ... OK +* checking package dependencies ... OK +* checking if this is a source package ... OK +* checking if there is a namespace ... OK +* checking for executable files ... OK +* checking for hidden files and directories ... OK +* checking for portable file names ... OK +* checking for sufficient/correct file permissions ... OK +* checking whether package ‘ribiosArg’ can be installed ... OK +* used C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0’ +* checking installed package size ... OK +* checking package directory ... OK +* checking DESCRIPTION meta-information ... OK +* checking top-level files ... OK +* checking for left-over files ... OK +* checking index information ... OK +* checking package subdirectories ... OK +* checking code files for non-ASCII characters ... OK +* checking R files for syntax errors ... OK +* checking whether the package can be loaded ... OK +* checking whether the package can be loaded with stated dependencies ... OK +* checking whether the package can be unloaded cleanly ... OK +* checking whether the namespace can be loaded with stated dependencies ... OK +* checking whether the namespace can be unloaded cleanly ... OK +* checking loading without being on the library search path ... OK +* checking whether startup messages can be suppressed ... OK +* checking dependencies in R code ... OK +* checking S3 generic/method consistency ... OK +* checking replacement functions ... OK +* checking foreign function calls ... OK +* checking R code for possible problems ... OK +* checking Rd files ... OK +* checking Rd metadata ... OK +* checking Rd cross-references ... OK +* checking for missing documentation entries ... OK +* checking for code/documentation mismatches ... OK +* checking Rd \usage sections ... OK +* checking Rd contents ... OK +* checking for unstated dependencies in examples ... OK +* checking line endings in C/C++/Fortran sources/headers ... OK +* checking line endings in Makefiles ... OK +* checking compilation flags in Makevars ... OK +* checking for GNU extensions in Makefiles ... OK +* checking for portable use of $(BLAS_LIBS) and $(LAPACK_LIBS) ... OK +* checking use of PKG_*FLAGS in Makefiles ... OK +* checking compiled code ... OK +* checking examples ... OK +* checking for unstated dependencies in ‘tests’ ... OK +* checking tests ... OK + Running ‘test_argParse.R’ + Running ‘test_argPresent_uninit.R’ + Running ‘test_getArg.R’ + Running ‘test_parseNumVec.R’ + Running ‘test_scriptName.R’ +* checking PDF version of manual ... OK +* DONE +Status: OK diff --git a/ribiosArg.Rcheck/00install.out b/ribiosArg.Rcheck/00install.out new file mode 100644 index 0000000..4e6b80f --- /dev/null +++ b/ribiosArg.Rcheck/00install.out @@ -0,0 +1,20 @@ +* installing *source* package ‘ribiosArg’ ... +** this is package ‘ribiosArg’ version ‘1.5.0’ +** using staged installation +** libs +using C compiler: ‘gcc (Ubuntu 11.4.0-1ubuntu1~22.04.2) 11.4.0’ +gcc -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/ribiosUtils/include' -I../inst/include -fpic -g -O2 -ffile-prefix-map=/build/r-base-xupQTd/r-base-4.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c argparse.c -o argparse.o +gcc -I"/usr/share/R/include" -DNDEBUG -I'/usr/local/lib/R/site-library/ribiosUtils/include' -I../inst/include -fpic -g -O2 -ffile-prefix-map=/build/r-base-xupQTd/r-base-4.5.2=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -c init.c -o init.o +gcc -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -o ribiosArg.so argparse.o init.o -L/usr/lib/R/lib -lR +installing to /home/david/projects/ribios/ribiosArg/ribiosArg.Rcheck/00LOCK-ribiosArg/00new/ribiosArg/libs +** R +** inst +** byte-compile and prepare package for lazy loading +** help +*** installing help indices +** building package indices +** testing if installed package can be loaded from temporary location +** checking absolute paths in shared objects and dynamic libraries +** testing if installed package can be loaded from final location +** testing if installed package keeps a record of temporary installation path +* DONE (ribiosArg) diff --git a/ribiosArg.Rcheck/Rdlatex.log b/ribiosArg.Rcheck/Rdlatex.log new file mode 100644 index 0000000..54c5de0 --- /dev/null +++ b/ribiosArg.Rcheck/Rdlatex.log @@ -0,0 +1,395 @@ +Hmm ... looks like a package +Converting parsed Rd's to LaTeX .. +Creating pdf output from LaTeX ... +Warning in texi2dvi(file = file, pdf = TRUE, clean = clean, quiet = quiet, : + texi2dvi script/program not available, using emulation +This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex) + restricted \write18 enabled. +entering extended mode +(./Rd2.tex +LaTeX2e <2021-11-15> patch level 1 +L3 programming layer <2022-01-21> +(/usr/share/texlive/texmf-dist/tex/latex/base/book.cls +Document Class: book 2021/10/04 v1.4n Standard LaTeX document class +(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo)) +(/usr/share/R/share/texmf/tex/latex/Rd.sty +(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty) +(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/verbatim.sty) +(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty +For additional information on amsmath, use the `?' option. +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty) +(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/mathrsfs.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty) +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/times.sty) +(/usr/share/texlive/texmf-dist/tex/latex/inconsolata/zi4.sty +`inconsolata-zi4' v1.12, 2019/05/17 Text macros for Inconsolata (msharpe) +(/usr/share/texlive/texmf-dist/tex/latex/xkeyval/xkeyval.sty +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkeyval.tex +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkvutils.tex +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/keyval.tex))))) +(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty +(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg) +(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty +(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty) +(/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty +(/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty)) +(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty) +(/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty) +(/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty) +(/usr/share/texlive/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty) +(/usr/share/texlive/texmf-dist/tex/latex/auxhook/auxhook.sty) +(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref-langpatches.def) +(/usr/share/texlive/texmf-dist/tex/generic/intcalc/intcalc.sty) +(/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/puenc.def) +(/usr/share/texlive/texmf-dist/tex/generic/bitset/bitset.sty +(/usr/share/texlive/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/base/atbegshi-ltx.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def +(/usr/share/texlive/texmf-dist/tex/latex/base/atveryend-ltx.sty) +(/usr/share/texlive/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty +(/usr/share/texlive/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty)))) +(/usr/share/texlive/texmf-dist/tex/latex/base/makeidx.sty) +Writing index file Rd2.idx +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1ptm.fd) +(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def) +No file Rd2.aux. +(/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +) (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty +(/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty) +(/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/ts1ptm.fd) +(/usr/share/texlive/texmf-dist/tex/latex/inconsolata/t1zi4.fd) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) +(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/ursfs.fd) [1{/var/lib/texmf/f +onts/map/pdftex/updmap/pdftex.map}] [2] [3] +Overfull \hbox (106.87898pt too wide) in paragraph at lines 189--190 +[]\T1/ptm/m/n/10 String de-scrib-ing op-tional ar-gu-ments. Syn-tax: []\T1/zi4/ +m/n/10 [,paramcnt1] [,paramcnt2]...[]\T1/ptm/m/n/10 . + +Overfull \hbox (1.64812pt too wide) in paragraph at lines 191--192 +\T1/ptm/m/n/10 Ex-am-ple: ``in-file out-file'' means the com-mand line has the +syn-tax []\T1/zi4/m/n/10 prog [-infile + +Overfull \hbox (1.05838pt too wide) in paragraph at lines 195--196 +[]\T1/ptm/m/n/10 Logical, are ex-tra un-prefixed pa-ram-e-ters al-lowed? If set + to []\T1/zi4/m/n/10 TRUE[]\T1/ptm/m/n/10 , the un-prefixed +[4] [5] (/usr/share/texlive/texmf-dist/tex/latex/inconsolata/ts1zi4.fd) +[6] [7] [8] [9] [10] +Overfull \hbox (2.34898pt too wide) in paragraph at lines 552--554 +[]\T1/ptm/m/n/10 The func-tion parses pa-ram-e-ters in the form of []\T1/zi4/m/ +n/10 KEY1=VAL1,KEY2=VAL2,KEY3=VAL3 []\T1/ptm/m/n/10 into []\T1/zi4/m/n/10 data. +frame[]\T1/ptm/m/n/10 . +[11] [12] [13] [14] [15] [16] [17] +No file Rd2.ind. +[18] (./Rd2.aux) + +Package rerunfilecheck Warning: File `Rd2.out' has changed. +(rerunfilecheck) Rerun to get outlines right +(rerunfilecheck) or use package `bookmark'. + + ) +(see the transcript file for additional information)pdfTeX warning (dest): name +{Rfn.commandArgs} has been referenced but does not exist, replaced by a fixed o +ne + +pdfTeX warning (dest): name{Rfn.strsplit} has been referenced but does not exis +t, replaced by a fixed one + +pdfTeX warning (dest): name{Rfn.trim} has been referenced but does not exist, r +eplaced by a fixed one + +{/usr/share/texlive/texmf-dist/fonts/enc/dvips/inconsolata/i4-ts1.enc}{/usr/sha +re/texlive/texmf-dist/fonts/enc/dvips/base/8r.enc}{/usr/share/texlive/texmf-dis +t/fonts/enc/dvips/inconsolata/i4-t1-0.enc} +Output written on Rd2.pdf (18 pages, 110549 bytes). +Transcript written on Rd2.log. +This is makeindex, version 2.15 [TeX Live 2022/dev] (kpathsea + Thai support). +Scanning input file Rd2.idx....done (50 entries accepted, 0 rejected). +Sorting entries....done (301 comparisons). +Generating output file Rd2.ind....done (80 lines written, 3 warnings). +Output written in Rd2.ind. +Transcript written in Rd2.ilg. +This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex) + restricted \write18 enabled. +entering extended mode +(./Rd2.tex +LaTeX2e <2021-11-15> patch level 1 +L3 programming layer <2022-01-21> +(/usr/share/texlive/texmf-dist/tex/latex/base/book.cls +Document Class: book 2021/10/04 v1.4n Standard LaTeX document class +(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo)) +(/usr/share/R/share/texmf/tex/latex/Rd.sty +(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty) +(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/verbatim.sty) +(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty +For additional information on amsmath, use the `?' option. +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty) +(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/mathrsfs.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty) +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/times.sty) +(/usr/share/texlive/texmf-dist/tex/latex/inconsolata/zi4.sty +`inconsolata-zi4' v1.12, 2019/05/17 Text macros for Inconsolata (msharpe) +(/usr/share/texlive/texmf-dist/tex/latex/xkeyval/xkeyval.sty +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkeyval.tex +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkvutils.tex +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/keyval.tex))))) +(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty +(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg) +(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty +(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty) +(/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty +(/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty)) +(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty) +(/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty) +(/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty) +(/usr/share/texlive/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty) +(/usr/share/texlive/texmf-dist/tex/latex/auxhook/auxhook.sty) +(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref-langpatches.def) +(/usr/share/texlive/texmf-dist/tex/generic/intcalc/intcalc.sty) +(/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/puenc.def) +(/usr/share/texlive/texmf-dist/tex/generic/bitset/bitset.sty +(/usr/share/texlive/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/base/atbegshi-ltx.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def +(/usr/share/texlive/texmf-dist/tex/latex/base/atveryend-ltx.sty) +(/usr/share/texlive/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty +(/usr/share/texlive/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty)))) +(/usr/share/texlive/texmf-dist/tex/latex/base/makeidx.sty) +Writing index file Rd2.idx +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1ptm.fd) +(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def) +(./Rd2.aux) (/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +) (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty +(/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty) +(/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty)) +(./Rd2.out) (./Rd2.out) +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/ts1ptm.fd) +(/usr/share/texlive/texmf-dist/tex/latex/inconsolata/t1zi4.fd) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) +(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/ursfs.fd) (./Rd2.toc [1{/var/ +lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]) [2] [3] [4] +Overfull \hbox (106.87898pt too wide) in paragraph at lines 189--190 +[]\T1/ptm/m/n/10 String de-scrib-ing op-tional ar-gu-ments. Syn-tax: []\T1/zi4/ +m/n/10 [,paramcnt1] [,paramcnt2]...[]\T1/ptm/m/n/10 . + +Overfull \hbox (1.64812pt too wide) in paragraph at lines 191--192 +\T1/ptm/m/n/10 Ex-am-ple: ``in-file out-file'' means the com-mand line has the +syn-tax []\T1/zi4/m/n/10 prog [-infile + +Overfull \hbox (1.05838pt too wide) in paragraph at lines 195--196 +[]\T1/ptm/m/n/10 Logical, are ex-tra un-prefixed pa-ram-e-ters al-lowed? If set + to []\T1/zi4/m/n/10 TRUE[]\T1/ptm/m/n/10 , the un-prefixed +[5] [6] (/usr/share/texlive/texmf-dist/tex/latex/inconsolata/ts1zi4.fd) +[7] [8] [9] [10] [11] +Overfull \hbox (2.34898pt too wide) in paragraph at lines 552--554 +[]\T1/ptm/m/n/10 The func-tion parses pa-ram-e-ters in the form of []\T1/zi4/m/ +n/10 KEY1=VAL1,KEY2=VAL2,KEY3=VAL3 []\T1/ptm/m/n/10 into []\T1/zi4/m/n/10 data. +frame[]\T1/ptm/m/n/10 . +[12] [13] [14] [15] [16] [17] (./Rd2.ind [18] + +LaTeX Font Warning: Font shape `T1/zi4/m/it' undefined +(Font) using `T1/zi4/m/n' instead on input line 16. + +[19]) (./Rd2.aux) + +LaTeX Font Warning: Some font shapes were not available, defaults substituted. + + +Package rerunfilecheck Warning: File `Rd2.out' has changed. +(rerunfilecheck) Rerun to get outlines right +(rerunfilecheck) or use package `bookmark'. + + ) +(see the transcript file for additional information)pdfTeX warning (dest): name +{Rfn.commandArgs} has been referenced but does not exist, replaced by a fixed o +ne + +pdfTeX warning (dest): name{Rfn.strsplit} has been referenced but does not exis +t, replaced by a fixed one + +pdfTeX warning (dest): name{Rfn.trim} has been referenced but does not exist, r +eplaced by a fixed one + +{/usr/share/texlive/texmf-dist/fonts/enc/dvips/inconsolata/i4-ts1.enc}{/usr/sha +re/texlive/texmf-dist/fonts/enc/dvips/base/8r.enc}{/usr/share/texlive/texmf-dis +t/fonts/enc/dvips/inconsolata/i4-t1-0.enc} +Output written on Rd2.pdf (19 pages, 125236 bytes). +Transcript written on Rd2.log. +This is makeindex, version 2.15 [TeX Live 2022/dev] (kpathsea + Thai support). +Scanning input file Rd2.idx....done (50 entries accepted, 0 rejected). +Sorting entries....done (301 comparisons). +Generating output file Rd2.ind....done (79 lines written, 3 warnings). +Output written in Rd2.ind. +Transcript written in Rd2.ilg. +This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex) + restricted \write18 enabled. +entering extended mode +(./Rd2.tex +LaTeX2e <2021-11-15> patch level 1 +L3 programming layer <2022-01-21> +(/usr/share/texlive/texmf-dist/tex/latex/base/book.cls +Document Class: book 2021/10/04 v1.4n Standard LaTeX document class +(/usr/share/texlive/texmf-dist/tex/latex/base/bk10.clo)) +(/usr/share/R/share/texmf/tex/latex/Rd.sty +(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty) +(/usr/share/texlive/texmf-dist/tex/generic/iftex/iftex.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/longtable.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/bm.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/alltt.sty) +(/usr/share/texlive/texmf-dist/tex/latex/tools/verbatim.sty) +(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/textcomp.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsmath.sty +For additional information on amsmath, use the `?' option. +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amstext.sty +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsgen.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsbsy.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsmath/amsopn.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amsfonts.sty) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/amssymb.sty) +(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/mathrsfs.sty) +(/usr/share/texlive/texmf-dist/tex/latex/base/fontenc.sty) +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/times.sty) +(/usr/share/texlive/texmf-dist/tex/latex/inconsolata/zi4.sty +`inconsolata-zi4' v1.12, 2019/05/17 Text macros for Inconsolata (msharpe) +(/usr/share/texlive/texmf-dist/tex/latex/xkeyval/xkeyval.sty +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkeyval.tex +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/xkvutils.tex +(/usr/share/texlive/texmf-dist/tex/generic/xkeyval/keyval.tex))))) +(/usr/share/texlive/texmf-dist/tex/latex/graphics/color.sty +(/usr/share/texlive/texmf-dist/tex/latex/graphics-cfg/color.cfg) +(/usr/share/texlive/texmf-dist/tex/latex/graphics-def/pdftex.def)) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref.sty +(/usr/share/texlive/texmf-dist/tex/generic/ltxcmds/ltxcmds.sty) +(/usr/share/texlive/texmf-dist/tex/generic/pdftexcmds/pdftexcmds.sty +(/usr/share/texlive/texmf-dist/tex/generic/infwarerr/infwarerr.sty)) +(/usr/share/texlive/texmf-dist/tex/generic/kvsetkeys/kvsetkeys.sty) +(/usr/share/texlive/texmf-dist/tex/generic/kvdefinekeys/kvdefinekeys.sty) +(/usr/share/texlive/texmf-dist/tex/generic/pdfescape/pdfescape.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hycolor/hycolor.sty) +(/usr/share/texlive/texmf-dist/tex/latex/letltxmacro/letltxmacro.sty) +(/usr/share/texlive/texmf-dist/tex/latex/auxhook/auxhook.sty) +(/usr/share/texlive/texmf-dist/tex/latex/kvoptions/kvoptions.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/pd1enc.def) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hyperref-langpatches.def) +(/usr/share/texlive/texmf-dist/tex/generic/intcalc/intcalc.sty) +(/usr/share/texlive/texmf-dist/tex/generic/etexcmds/etexcmds.sty) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/puenc.def) +(/usr/share/texlive/texmf-dist/tex/generic/bitset/bitset.sty +(/usr/share/texlive/texmf-dist/tex/generic/bigintcalc/bigintcalc.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/base/atbegshi-ltx.sty)) +(/usr/share/texlive/texmf-dist/tex/latex/hyperref/hpdftex.def +(/usr/share/texlive/texmf-dist/tex/latex/base/atveryend-ltx.sty) +(/usr/share/texlive/texmf-dist/tex/latex/rerunfilecheck/rerunfilecheck.sty +(/usr/share/texlive/texmf-dist/tex/generic/uniquecounter/uniquecounter.sty)))) +(/usr/share/texlive/texmf-dist/tex/latex/base/makeidx.sty) +Writing index file Rd2.idx +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/t1ptm.fd) +(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def) +(./Rd2.aux) (/usr/share/texlive/texmf-dist/tex/context/base/mkii/supp-pdf.mkii +[Loading MPS to PDF converter (version 2006.09.02).] +) (/usr/share/texlive/texmf-dist/tex/latex/hyperref/nameref.sty +(/usr/share/texlive/texmf-dist/tex/latex/refcount/refcount.sty) +(/usr/share/texlive/texmf-dist/tex/generic/gettitlestring/gettitlestring.sty)) +(./Rd2.out) (./Rd2.out) +(/usr/share/texlive/texmf-dist/tex/latex/psnfss/ts1ptm.fd) +(/usr/share/texlive/texmf-dist/tex/latex/inconsolata/t1zi4.fd) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsa.fd) +(/usr/share/texlive/texmf-dist/tex/latex/amsfonts/umsb.fd) +(/usr/share/texlive/texmf-dist/tex/latex/jknapltx/ursfs.fd) (./Rd2.toc [1{/var/ +lib/texmf/fonts/map/pdftex/updmap/pdftex.map}]) [2] [3] [4] +Overfull \hbox (106.87898pt too wide) in paragraph at lines 189--190 +[]\T1/ptm/m/n/10 String de-scrib-ing op-tional ar-gu-ments. Syn-tax: []\T1/zi4/ +m/n/10 [,paramcnt1] [,paramcnt2]...[]\T1/ptm/m/n/10 . + +Overfull \hbox (1.64812pt too wide) in paragraph at lines 191--192 +\T1/ptm/m/n/10 Ex-am-ple: ``in-file out-file'' means the com-mand line has the +syn-tax []\T1/zi4/m/n/10 prog [-infile + +Overfull \hbox (1.05838pt too wide) in paragraph at lines 195--196 +[]\T1/ptm/m/n/10 Logical, are ex-tra un-prefixed pa-ram-e-ters al-lowed? If set + to []\T1/zi4/m/n/10 TRUE[]\T1/ptm/m/n/10 , the un-prefixed +[5] [6] (/usr/share/texlive/texmf-dist/tex/latex/inconsolata/ts1zi4.fd) +[7] [8] [9] [10] [11] +Overfull \hbox (2.34898pt too wide) in paragraph at lines 552--554 +[]\T1/ptm/m/n/10 The func-tion parses pa-ram-e-ters in the form of []\T1/zi4/m/ +n/10 KEY1=VAL1,KEY2=VAL2,KEY3=VAL3 []\T1/ptm/m/n/10 into []\T1/zi4/m/n/10 data. +frame[]\T1/ptm/m/n/10 . +[12] [13] [14] [15] [16] [17] (./Rd2.ind [18] + +LaTeX Font Warning: Font shape `T1/zi4/m/it' undefined +(Font) using `T1/zi4/m/n' instead on input line 16. + +[19]) (./Rd2.aux) + +LaTeX Font Warning: Some font shapes were not available, defaults substituted. + + ) +(see the transcript file for additional information)pdfTeX warning (dest): name +{Rfn.commandArgs} has been referenced but does not exist, replaced by a fixed o +ne + +pdfTeX warning (dest): name{Rfn.strsplit} has been referenced but does not exis +t, replaced by a fixed one + +pdfTeX warning (dest): name{Rfn.trim} has been referenced but does not exist, r +eplaced by a fixed one + +{/usr/share/texlive/texmf-dist/fonts/enc/dvips/inconsolata/i4-ts1.enc}{/usr/sha +re/texlive/texmf-dist/fonts/enc/dvips/base/8r.enc}{/usr/share/texlive/texmf-dis +t/fonts/enc/dvips/inconsolata/i4-t1-0.enc} +Output written on Rd2.pdf (19 pages, 125700 bytes). +Transcript written on Rd2.log. +Saving output to ‘ribiosArg-manual.pdf’ ... +Done +You may want to clean up by 'rm -Rf /tmp/RtmpmVBwlX/Rd2pdf58b2d29f0214f' diff --git a/ribiosArg.Rcheck/ribiosArg-Ex.R b/ribiosArg.Rcheck/ribiosArg-Ex.R new file mode 100644 index 0000000..16c6c5b --- /dev/null +++ b/ribiosArg.Rcheck/ribiosArg-Ex.R @@ -0,0 +1,284 @@ +pkgname <- "ribiosArg" +source(file.path(R.home("share"), "R", "examples-header.R")) +options(warn = 1) +library('ribiosArg') + +base::assign(".oldSearch", base::search(), pos = 'CheckExEnv') +base::assign(".old_wd", base::getwd(), pos = 'CheckExEnv') +cleanEx() +nameEx("argGet") +### * argGet + +flush(stderr()); flush(stdout()) + +### Name: argGet +### Title: Parse an argument +### Aliases: argGet + +### ** Examples + + + + + +cleanEx() +nameEx("argGetPos") +### * argGetPos + +flush(stderr()); flush(stdout()) + +### Name: argGetPos +### Title: Parse an argument with the given position +### Aliases: argGetPos + +### ** Examples + + + + + +cleanEx() +nameEx("argParse") +### * argParse + +flush(stderr()); flush(stdout()) + +### Name: argParse +### Title: Parser of command-line parameters in BIOS style +### Aliases: argParse argPresent + +### ** Examples + + + + + +cleanEx() +nameEx("existArg") +### * existArg + +flush(stderr()); flush(stdout()) + +### Name: existArg +### Title: Test if named arguments exists +### Aliases: existArg + +### ** Examples + +comm <- paste(c("Rscript --vanilla -e", "'", "library(ribiosArg);", + "existArg(c(\"opt\", \"opt2\", \"opt3\"))", "'", + "-opt abc -opt3"), collapse=" ") +system(comm) + + + +cleanEx() +nameEx("isDebugging") +### * isDebugging + +flush(stderr()); flush(stdout()) + +### Name: isDebugging +### Title: Test whether the environment is set for debugging +### Aliases: isDebugging + +### ** Examples + +isDebugging() +unsetDebug() +isDebugging() +setDebug() + + + + +cleanEx() +nameEx("makeFactor") +### * makeFactor + +flush(stderr()); flush(stdout()) + +### Name: makeFactor +### Title: Make a factor +### Aliases: makeFactor + +### ** Examples + +makeFactor(c("A", "B", "C", "C", "A"), levels=LETTERS[3:1]) +makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), + levels=c("A 1", "C 3", "B 2"), + make.names=TRUE) +makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), + levels=c("A 1", "C 3", "B 2"), + make.names=FALSE) +makeFactor(c("A 1", "B 2", "C 3", "C 3", "A 1"), + levels=c("A 1", "C 3", "B 2"), + make.names=FALSE, verbose=TRUE) + + + +cleanEx() +nameEx("parseFactor") +### * parseFactor + +flush(stderr()); flush(stdout()) + +### Name: parseFactor +### Title: Parse a character string into factor +### Aliases: parseFactor + +### ** Examples + +parseFactor("A,B,C,B,A", rlevels="A,B,C") + +rgroup <- "A,B,C,D,B,C,A,D,B" +rlevels <- "D,A,B,C" +parseFactor(rgroup, rlevels) + +groups <- c("ATest", "Control", "Control", "ATest") +levels <- c("Control", "ATest") +makeFactor(groups, levels) + +# if 'groups' is a factor and 'levels' NULL or missing, its levels are respected +groups <- factor(c("B", "C", "A", "D"), levels=c("D","C","A","B")) +makeFactor(groups) + + + + + +cleanEx() +nameEx("parseNumVec") +### * parseNumVec + +flush(stderr()); flush(stdout()) + +### Name: parseNumVec +### Title: Parse a character string into a numveric vector +### Aliases: parseNumVec + +### ** Examples + +parseNumVec("3,7,9", expLen=3) + + + +cleanEx() +nameEx("parsePairs") +### * parsePairs + +flush(stderr()); flush(stdout()) + +### Name: parsePairs +### Title: Parse key-value pairs from a character string +### Aliases: parsePairs + +### ** Examples + + +parsePairs("A=3,B=4,C=5", collapse=",", sep="=") +parsePairs("A:3|B:4|C:5", collapse="|", sep=":") + + + + +cleanEx() +nameEx("parseStrings") +### * parseStrings + +flush(stderr()); flush(stdout()) + +### Name: parseStrings +### Title: Parse a character string into string vectors +### Aliases: parseStrings + +### ** Examples + +parseStrings("veni, vidi, vici") +parseStrings("veni, vidi, vici", trim=FALSE) +parseStrings("I came, I saw, I conquered") + +# options are trimmed +parseStrings("a,b,\tc,d\n") +# it works also with only one option +parseStrings("a") +# more than one separators +parseStrings("a,b,c;d", collapse=",|;") + + + +cleanEx() +nameEx("scriptInit") +### * scriptInit + +flush(stderr()); flush(stdout()) + +### Name: scriptInit +### Title: Prepare the environment for a script +### Aliases: scriptInit initScript + +### ** Examples + + + + +cleanEx() +nameEx("scriptName") +### * scriptName + +flush(stderr()); flush(stdout()) + +### Name: scriptName +### Title: Returns the file name of the Rscript being executed +### Aliases: scriptName + +### ** Examples + + + + + +cleanEx() +nameEx("scriptPath") +### * scriptPath + +flush(stderr()); flush(stdout()) + +### Name: scriptPath +### Title: Returns the path of the Rscript being executed +### Aliases: scriptPath + +### ** Examples + + + + + +cleanEx() +nameEx("scriptSkeleton") +### * scriptSkeleton + +flush(stderr()); flush(stdout()) + +### Name: scriptSkeleton +### Title: Generate a Rscript with its skeleton +### Aliases: scriptSkeleton + +### ** Examples + +scriptSkeleton(file = file.path(tempdir(), "myscript.R")) + + + +### *