2016-12-14 73 views
0

我在R中使用docopt,但我希望python解决方案也适用于我。参数默认为docopt

library(docopt) 

doc = 'Usage: 
    script.r [<filename>] 

Arguments: 
    <filename> The input filename [default: file.txt] 
' 

docopt(doc)$filename 

给我NULL当我的期望是file.txt。或者换一种说法,我想这两个命令具有相同的行为:

Rscript script.r 
Rscript script.r file.txt 
+0

看起来像一个docopt设计决策? https://github.com/docopt/docopt/issues/214 – Spacedman

回答

0

默认值仅适用于拥有这样一个参数选项:不能指定

--filename=FILENAME The input filename [default: file.txt] 

默认值争论。你也许可以改变你的程序来使用带有参数的选项呢?