【发布时间】:2016-08-10 14:21:31
【问题描述】:
我通常在 Python 中使用 argparse,在 R 中使用 docopt。我在 argparse 中错过的一个我还没有在 docopt 中发现的功能是能够为每个参数指定所需的数据类型。例如,在 argparse 中,我需要一个整数输入,使用
parser.add_argument("square", help="display a square of a given number",
type=int)
在 docopt / R 中,我在文档中找不到任何关于需要特定数据类型的内容。
-s <square>, --square=<square> display a square of a given number #additional option to require integer input?
在 Python 版本的 docopt GitHub repo 上有一个封闭的issue,这似乎表明这不是基本 docopt 的一部分,并为 Python 提供了解决方案,但这并不直接适用于 R。任何人都可以提供在 R 中使用 docopt 验证参数输入的任何建议/更优雅的方法?
【问题讨论】: