1
在使用R创建命令行工具时,我决定使用docopt package。它适用于传递标志,但我无法弄清楚如何传递两个数字值。请参见下面的代码:无法通过docopt包传递两个数值参数
#! /usr/bin/Rscript
'usage: ./test.R [-lr <low> -hr <high>]
options:
-h --help Shows this screen
-lr --low <low> Passes low risk investiment
-hr --high <high> Passes high risk investiment' -> doc
library(docopt)
# retrieve the command-line arguments
opts <- docopt(doc)
# what are the options? Note that stripped versions of the parameters are added to the returned list
cat(opts$high)
cat(opts$low)
str(opts)
每当我试着用./test.R -lr 2000 -hr 4000
它警告我说的方法包被加载并返回没有别的运行。
- 这是什么错误?
谢谢您的详细解答,但是它必须是R(R版本3.4.1)中的一个bug,来自CRAN的docopt,因为它不起作用。 –
好的,对不起,我最初将其解释为docopt中的一个问题(与原始版本不兼容),而不是R实现(似乎与任一版本窒息)。我发现你已经[已经提交了一个错误报告](https://github.com/docopt/docopt.R/issues/32),在我之前。 – r2evans
我发现了错误。 docopt的R迭代在用法部分不处理./test.R,它必须是test.R –