r-argparse
command-line optional and positional argument parser
Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 2 committers (50.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (16.8%) to scientific vocabulary
Last synced: 10 months ago
·
JSON representation
Repository
command-line optional and positional argument parser
Basic Info
- Host: GitHub
- Owner: trevorld
- License: gpl-2.0
- Language: R
- Default Branch: master
- Homepage: https://trevorldavis.com/R/argparse/
- Size: 157 KB
Statistics
- Stars: 107
- Watchers: 4
- Forks: 11
- Open Issues: 3
- Releases: 15
Created about 13 years ago
· Last pushed about 1 year ago
Metadata Files
Readme
Changelog
Contributing
License
README.rst
argparse: Command line optional and positional argument parser
==============================================================
.. image:: https://www.r-pkg.org/badges/version/argparse
:target: https://cran.r-project.org/package=argparse
:alt: CRAN Status Badge
.. image:: https://github.com/trevorld/r-argparse/actions/workflows/R-CMD-check.yaml/badge.svg?branch=master
:target: https://github.com/trevorld/r-argparse/actions
:alt: R-CMD-check
.. image:: https://codecov.io/github/trevorld/r-argparse/branch/master/graph/badge.svg
:target: https://app.codecov.io/github/trevorld/r-argparse?branch=master
:alt: Coverage Status
.. image:: https://cranlogs.r-pkg.org/badges/argparse
:target: https://cran.r-project.org/package=argparse
:alt: RStudio CRAN mirror downloads
.. raw:: html
``argparse`` is an R package which provides a command line parser to
be used with Rscript to write "#!" shebang scripts that gracefully
accept positional and optional arguments and automatically generate usage.
To install the latest version released on CRAN use the following command::
> install.packages("argparse")
To install the development version use the following command::
> remotes::install_github("trevorld/r-argparse")
dependencies
------------
The package has a Python dependency.
It is easily satisfied if you have Python (version 3.2 or higher) on your PATH.
Read the INSTALL file for more information if this doesn't describe you.
Additionally this package depends on the R packages ``R6``, ``findpython``, and ``jsonlite``.
To run the unit tests you will need the suggested R package ``testthat`` and in
order to build the vignette you will need the suggested R package ``knitr``
which in turn probably requires the system tool ``pandoc``::
sudo apt install pandoc
examples
--------
::
> library("argparse")
> parser <- ArgumentParser(description='Process some integers')
> parser$add_argument('integers', metavar='N', type="integer", nargs='+',
+ help='an integer for the accumulator')
> parser$add_argument('--sum', dest='accumulate', action='store_const',
+ const='sum', default='max',
+ help='sum the integers (default: find the max)')
> parser$print_help()
usage: PROGRAM [-h] [--sum] N [N ...]
Process some integers
positional arguments:
N an integer for the accumulator
optional arguments:
-h, --help show this help message and exit
--sum sum the integers (default: find the max)
Default args for ``ArgumentParser()$parse_args`` are ``commandArgs(TRUE)``
which is what you'd want for an Rscript but not for interactive use::
> args <- parser$parse_args(c("--sum", "1", "2", "3"))
> accumulate_fn <- get(args$accumulate)
> print(accumulate_fn(args$integers))
[1] 6
Beginning with version 2.0 ``argparse`` also supports argument groups::
> parser = ArgumentParser(prog='PROG', add_help=FALSE)
> group1 = parser$add_argument_group('group1', 'group1 description')
> group1$add_argument('foo', help='foo help')
> group2 = parser$add_argument_group('group2', 'group2 description')
> group2$add_argument('--bar', help='bar help')
> parser$print_help()
usage: PROG [-h] [--bar BAR] foo
optional arguments:
-h, --help show this help message and exit
group1:
group1 description
foo foo help
group2:
group2 description
--bar BAR bar help
as well as mutually exclusive groups::
> parser = ArgumentParser(prog='PROG')
> group = parser$add_mutually_exclusive_group()
> group$add_argument('--foo', action='store_true')
> group$add_argument('--bar', action='store_false')
> parser$parse_args('--foo')
$bar
[1] TRUE
$foo
[1] TRUE
> parser$parse_args('--bar')
$bar
[1] FALSE
$foo
[1] FALSE
> parser$parse_args(c('--foo', '--bar'))
Error in "argparse::parse_args_output(output)" : parse error:
usage: PROG [-h] [--foo | --bar]
PROG: error: argument --bar: not allowed with argument --foo
and even basic support for sub-commands!::
> # create the top-level parser
> parser = ArgumentParser(prog='PROG')
> parser$add_argument('--foo', action='store_true', help='foo help')
> subparsers = parser$add_subparsers(help='sub-command help')
> # create the parser for the "a" command
> parser_a = subparsers$add_parser('a', help='a help')
> parser_a$add_argument('bar', type='integer', help='bar help')
> # create the parser for the "b" command
> parser_b = subparsers$add_parser('b', help='b help')
> parser_b$add_argument('--baz', choices='XYZ', help='baz help')
> # parse some argument lists
> parser$parse_args(c('a', '12'))
$bar
[1] 12
$foo
[1] FALSE
> parser$parse_args(c('--foo', 'b', '--baz', 'Z'))
$baz
[1] "Z"
$foo
[1] TRUE
> parser$print_help()
usage: PROG [-h] [--foo] {a,b} ...
positional arguments:
{a,b} sub-command help
a a help
b b help
optional arguments:
-h, --help show this help message and exit
--foo foo help
> parser_a$print_help()
usage: PROG a [-h] bar
positional arguments:
bar bar help
optional arguments:
-h, --help show this help message and exit
> parser_b$print_help()
usage: PROG b [-h] [--baz {X,Y,Z}]
optional arguments:
-h, --help show this help message and exit
--baz {X,Y,Z} baz help
Owner
- Name: Trevor L Davis
- Login: trevorld
- Kind: user
- Location: Stanford, CA
- Repositories: 29
- Profile: https://github.com/trevorld
Studies electricity markets
GitHub Events
Total
- Create event: 5
- Release event: 2
- Issues event: 7
- Watch event: 5
- Delete event: 3
- Issue comment event: 9
- Push event: 6
- Pull request event: 5
Last Year
- Create event: 5
- Release event: 2
- Issues event: 7
- Watch event: 5
- Delete event: 3
- Issue comment event: 9
- Push event: 6
- Pull request event: 5
Committers
Last synced: about 1 year ago
Top Committers
| Name | Commits | |
|---|---|---|
| Trevor L Davis | t****s@g****m | 139 |
| trevor | t****d@s****u | 8 |
Committer Domains (Top 20 + Academic)
stanford.edu: 1
Issues and Pull Requests
Last synced: 10 months ago
All Time
- Total issues: 52
- Total pull requests: 5
- Average time to close issues: 3 months
- Average time to close pull requests: about 17 hours
- Total issue authors: 32
- Total pull request authors: 2
- Average comments per issue: 2.13
- Average comments per pull request: 0.4
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 3
- Pull requests: 3
- Average time to close issues: 5 days
- Average time to close pull requests: 18 minutes
- Issue authors: 2
- Pull request authors: 1
- Average comments per issue: 3.0
- Average comments per pull request: 0.0
- Merged pull requests: 3
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- trevorld (13)
- dariober (6)
- agilly (2)
- vreuter (2)
- metasoarous (2)
- DominikMueller64 (1)
- capnrefsmmat (1)
- WaterKnight1998 (1)
- oliverdrechsel (1)
- chlige (1)
- oliverbothe (1)
- mariellep (1)
- krisspnet (1)
- MLopez-Ibanez (1)
- ssh352 (1)
Pull Request Authors
- trevorld (6)
- paul-newell (1)
Top Labels
Issue Labels
enhancement (16)
bug (12)
question (1)
refactoring (1)
Pull Request Labels
Packages
- Total packages: 2
-
Total downloads:
- cran 4,172 last-month
- Total docker downloads: 362,935
-
Total dependent packages: 2
(may contain duplicates) -
Total dependent repositories: 46
(may contain duplicates) - Total versions: 33
- Total maintainers: 1
cran.r-project.org: argparse
Command Line Optional and Positional Argument Parser
- Homepage: https://github.com/trevorld/r-argparse
- Documentation: http://cran.r-project.org/web/packages/argparse/argparse.pdf
- License: GPL-2 | GPL-3 [expanded from: GPL (≥ 2)]
-
Latest release: 2.2.5
published over 1 year ago
Rankings
Stargazers count: 4.0%
Dependent repos count: 5.3%
Forks count: 6.3%
Downloads: 7.2%
Average: 9.6%
Dependent packages count: 13.7%
Docker downloads count: 20.9%
Maintainers (1)
Last synced:
10 months ago
conda-forge.org: r-argparse
- Homepage: https://github.com/trevorld/r-argparse
- License: GPL-2.0-or-later
-
Latest release: 2.1.6
published almost 4 years ago
Rankings
Dependent repos count: 8.1%
Average: 34.6%
Stargazers count: 35.0%
Forks count: 43.7%
Dependent packages count: 51.6%
Last synced:
10 months ago
Dependencies
DESCRIPTION
cran
- R >= 3.6.0 depends
- R6 * imports
- findpython * imports
- jsonlite * imports
- knitr >= 1.15.19 suggests
- rmarkdown * suggests
- testthat * suggests
.github/workflows/R-CMD-check.yaml
actions
- actions/checkout v2 composite
- actions/upload-artifact main composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite