Description Usage Arguments Value Note Examples
This function is intended to find the position of commandline arguments. Under usual circumstances this is called from other functions but has been exported for the user. It is intentionally restricted to only take 2 possible argument indicators, but does not in itself restrict the format of those argument. These restrictions should be checked before calling the function. The check itself is performed in optimized c++ code.
1 | find_args(args = commandArgs(TRUE), sarg, larg)
|
args |
vector of commandline arguments. Defaults to commandArgs(TRUE) |
sarg |
short argument indicator (one letter arguments). No default |
larg |
long argument indicator (one or more letter). |
An integer vector indicating the positions that started with either sarg or larg. If both are provided the integer indicates larg over sarg to avoid any confusion between "-" and "–" (or equivalent). The vector contains an attribute 'argLen' indicating the end position for the argument indicator.
The function checks whether the argument indicator is followed by an empty space and throws an error if this is the case. This follows the output syntax from commandArg, which cannot have "spaces" in arguments unless quoted.
The function does not check for other types of invalid arguments (duplicates, invalid symbol names etc.). These checks should be caught with pattern matching.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | # Simple argument finding
find_args(c('--abcd', '-d', 'hello', '--ff'), '-', '--')
find_args(c('--abcd', '-d', 'hello', '--ff'), '-')
find_args(c('--abcd', '-d', 'hello', '--ff'), '--')
# Example with help
find_args('-h', '-', '--')
find_args('--help', '-', '--')
# Note that this does not find help:
find_args('--help', '-')
# Example with alternative indicator
find_args('/h', , '/')
## Not run:
# Example of an error:
find_args(c('-- ', '-d', 'hello', '--ff'), '-', '--')
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.