File: add_make_option.Rd

package info (click to toggle)
r-cran-optparse 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 236 kB
  • sloc: sh: 9; makefile: 1
file content (105 lines) | stat: -rw-r--r-- 4,079 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
\name{make_option}
\alias{add_option}
\alias{make_option}
\title{Functions to enable our OptionParser to recognize specific command line
options.}
\usage{
  make_option(opt_str, action = "store", type = NULL,
    dest = NULL, default = NULL, help = "", metavar = NULL)

  add_option(object, opt_str, action = "store",
    type = NULL, dest = NULL, default = NULL, help = "",
    metavar = NULL)
}
\arguments{
  \item{object}{An instance of the \code{OptionParser}
  class}

  \item{opt_str}{A character vector containing the string
  of the desired long flag comprised of \dQuote{--}
  followed by a letter and then a sequence of alphanumeric
  characters and optionally a string of the desired short
  flag comprised of the \dQuote{-} followed by a letter.}

  \item{action}{A character string that describes the
  action \code{optparse} should take when it encounters an
  option, either \dQuote{store}, \dQuote{store_true}, or
  \dQuote{store_false}.  The default is \dQuote{store}
  which signifies that \code{optparse} should store the
  specified following value if the option is found on the
  command string.  \dQuote{store_true} stores \code{TRUE}
  if the option is found and \dQuote{store_false} stores
  \code{FALSE} if the option is found.}

  \item{type}{A character string that describes specifies
  which data type should be stored, either
  \dQuote{logical}, \dQuote{integer}, \dQuote{double},
  \dQuote{complex}, or \dQuote{character}.  Default is
  \dQuote{logical} if \code{action %in% c("store_true",
  store_false)}, \code{typeof(default)} if \code{action ==
  "store"} and default is not \code{NULL} and
  \dQuote{character} if \code{action == "store"} and
  default is \code{NULL}.  \dQuote{numeric} will be
  converted to \dQuote{double}.}

  \item{dest}{A character string that specifies what field
  in the list returned by \code{parse_args} should
  \code{optparse} store option values.  Default is derived
  from the long flag in \code{opt_str}.}

  \item{default}{The default value \code{optparse} should
  use if it does not find the option on the command line.
  Default is derived from the long flag in \code{opt_str}.}

  \item{help}{A character string describing the option to
  be used by \code{print_help} in generating a usage
  message.  \code{\%default} will be substituted by the
  value of \code{default}.}

  \item{metavar}{A character string that stands in for the
  option argument when printing help text.  Default is the
  value of \code{dest}.}
}
\value{
  Both \code{make_option} and \code{add_option} return
  instances of class \code{OptionParserOption}.
}
\description{
  \code{add_option} adds a option to a prexisting
  \code{OptionParser} instance whereas \code{make_option}
  is used to create a list of \code{OptionParserOption}
  instances that will be used in the \code{option_list}
  argument of the \code{OptionParser} function to create a
  new \code{OptionParser} instance.
}
\examples{
make_option("--longflag")
   make_option(c("-l", "--longflag"))
   make_option("--integer", type="integer", default=5)
   make_option("--integer", default=as.integer(5))  # same as previous

   # examples from package vignette
   make_option(c("-v", "--verbose"), action="store_true", default=TRUE,
       help="Print extra output [default]")
   make_option(c("-c", "--count"), type="integer", default=5,
       help="Number of random normals to generate [default \%default]",
       metavar="number")
   make_option("--generator", default="rnorm",
       help = "Function to generate random deviates [default \\"\%default\\"]")
   make_option("--mean", default=0,
       help="Mean if generator == \\"rnorm\\" [default \%default]")
   make_option("--sd", default=1, metavar="standard deviation",
       help="Standard deviation if generator == \\"rnorm\\" [default \%default]")
}
\author{
  Trevor Davis.
}
\references{
  Python's \code{optparse} library, which inspires this
  package, is described here:
  \url{http://docs.python.org/library/optparse.html}
}
\seealso{
  \code{\link{parse_args}} \code{\link{OptionParser}}
}