docopt/docopt.R

Running docopt in RStudio produces an error, but on command line works fine

Closed this issue · 2 comments

bc2zb commented

I believe this is related to this issue. I'm working on a command line tool using docopt. When I run cyttools.R, I get the usage error seen in the issue linked above.

`
require(docopt)
Loading required package: docopt
require(methods)

"
Usage:
cyttools.R (-h | --help | --version)
cyttools.R [--cluster=] DIR

Description: This program performs automated high parameter cytometry data analysis.
Options:
--version Show the current version.
--cluster= [default: FlowType] The algorithm to use for clustering.

Arguments:

DIR Provide directory for files to be analyzed.
" -> doc

args <- docopt(doc)
Error:
usage: cyttools.R (-h | --help | --version)

usage: cyttools.R [--cluster=] DIR`

But if I run at the command line, it works fine.
`Rscript cyttools.R /some/dir/

Loading required package: docopt
Loading required package: methods

Preparing to run analysis using FlowType on /Users/bc2zb/BTSync/

Loading required package: docopt
Loading required package: methods

Loading arguments from /Users/bc2zb/BTSync/ `

This is frustrating because I can't effectively prototype from within Rstudio. Am I doing something wrong? Also, sorry about any formatting issues, I'm still new to this sort of interaction, and let me know if I should include anything else.

`sessionInfo()
R version 3.4.0 (2017-04-21)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS Sierra 10.12.5

Matrix products: default
BLAS: /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats graphics grDevices utils datasets methods base

other attached packages:`

When you use RStudio you don't have any command-line args because you are running interactively in a GUI application. Therefore, when you args <- docopt(doc) there are no arguments and it gives you the error.

If you wanna test from RStudio, you have to provide the arguments yourself, just like you did with Rscript: args <- docopt(doc, "/some/dir/").

bc2zb commented

I understand that. My issue was I couldn't even get docopt to make the empty object, but maybe that's intentional. I mean, it's not a huge issue, it works and I've built out the tool pretty extensively at this point.