Commit 7313f011 authored by Dirk Eddelbuettel's avatar Dirk Eddelbuettel

Import Upstream version 1.20.2

parent b19226fa
Package: getopt
Type: Package
Title: C-Like 'getopt' Behavior
Version: 1.20.1
Version: 1.20.2
Author: Allen Day.
Contributions from Trevor L Davis and Roman Zenka.
Maintainer: Trevor L Davis <trevor.l.davis@gmail.com>
......@@ -17,6 +17,6 @@ License: GPL (>= 2)
Suggests: testthat
RoxygenNote: 6.0.1
NeedsCompilation: no
Packaged: 2017-11-29 22:23:04 UTC; trevorld
Packaged: 2018-02-16 04:46:12 UTC; trevorld
Repository: CRAN
Date/Publication: 2017-11-29 23:47:17 UTC
Date/Publication: 2018-02-16 11:18:58 UTC
b234ee4d69f5fce4486a80fdaf4a4263 *COPYING
633c7bb643b66fbcede364fca8c8e538 *DESCRIPTION
a2538666cbeb4f1a012a9ccbe7e430cb *DESCRIPTION
d400adb3d8a7edbac587ac399fdeb451 *NAMESPACE
df3d63cace1715e6ff923097ea414c18 *NEWS
8c78d6f8d7d6ca6db34c45529501cb11 *R/getopt.R
e374b85f40f7549cbdb66c9065c1f1ec *R/utils.R
83dbf2fb9391e80d1210814704413cae *NEWS
7a0ae3a4fa75f47310e5837f4c996d7a *R/getopt.R
5121860755a766ac2c250aa5909680bf *R/utils.R
5a2cda954866c5d7604a71b09cf09cbd *exec/example.R
6f64f9d572b196c7a8b134220425a06a *man/get_Rscript_filename.Rd
c1d20843902006a2d52e480fe841037f *man/getopt.Rd
9ba3ea21bace8ecaa9b3687fa55f7efe *man/sort_list.Rd
35fe6c4707e36c320771156c47cc943f *tests/run-all.R
554652391069d23674fe3c317646b75a *tests/testthat/test-getopt.R
b4854c3eb3288028b222bf3bb54c1b6e *tests/testthat/test-getopt.R
getopt 1.20.2
=============
* Now allows one to pass an empty string to a character option.
getopt 1.20.1
=============
* Now explicitly imports the ``na.omit`` method from the ``stats`` package.
......
# Copyright (c) 2008-2010 Allen Day
# Copyright (c) 2011-2015, 2017 Trevor L. Davis <trevor.l.davis@stanford.edu>
# Copyright (c) 2011-2015, 2017-2018 Trevor L. Davis <trevor.l.davis@gmail.com>
#
# This file is free software: you may copy, redistribute and/or modify it
# under the terms of the GNU General Public License as published by the
......@@ -289,7 +289,8 @@ getopt = function (spec=NULL,opt=commandArgs(TRUE),command=get_Rscript_filename(
this.flag = NA
this.argument = NA
kv = strsplit(optstring, '=')[[1]]
if ( !is.na(kv[2]) ) {
# if ( !is.na(kv[2]) ) {
if ( grepl('=', optstring) ) {
this.flag = kv[1]
this.argument = paste(kv[-1], collapse="=")
} else {
......@@ -320,8 +321,11 @@ getopt = function (spec=NULL,opt=commandArgs(TRUE),command=get_Rscript_filename(
#otherwise assign the argument to the flag
} else {
mode = spec[rowmatch, col.mode]
tryCatch(storage.mode(this.argument) <- mode,
warning_msg <- tryCatch(storage.mode(this.argument) <- mode,
warning = function(w) {warning(paste(mode, "expected, got", dQuote(this.argument)))})
if( is.na(this.argument) && !grepl("expected, got", warning_msg) ) {
warning(paste('long flag', this.flag, 'given a bad argument'))
}
result[spec[rowmatch, col.long.name]] = this.argument
i = i + 1
next
......
# Copyright (c) 2011-2013 Trevor L. Davis <trevor.l.davis@stanford.edu>
# Copyright (c) 2011-2013 Trevor L. Davis <trevor.l.davis@gmail.com>
#
# This file is free software: you may copy, redistribute and/or modify it
# under the terms of the GNU General Public License as published by the
......
......@@ -67,6 +67,14 @@ test_that("numeric is cast to double", {
spec = matrix(c("count", "c", 1, "numeric"), ncol=4, byrow=TRUE)
getopt(spec, c("-c", "-55.0"))
})
test_that("empty strings are handled correctly for mandatory character arguments", {
spec = matrix(c("string", "s", 1, "character",
"number", "n", 1, "numeric"), ncol=4, byrow=TRUE)
expect_equal(getopt(spec, c("--string=foo"))$string, "foo")
expect_equal(getopt(spec, c("--string="))$string, "")
expect_warning(getopt(spec, c("--number=")))
})
test_that("negative numbers are handled correctly", {
# Issue if negative number preceded by space instead of '=' reported by Roman Zenka
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment