MLMH
MLMH

Reputation: 141

docopt in R returning the same script

I am fairly new using docopt for passing arguments in R.

I have something like this:

#!/n/tools/script
##First read in the arguments listed at the command line
library(docopt)
require(methods)

"
Usage:
  Finding.R [options] FILE

  Description:   
  Options:
   --help                        Show this screen
   --version                     Show the current version.
   --Threshold=<Threshold>       [default: 250]
   --output=OUTPUT               [default: out.txt]
   --color=<color>               [default: FALSE]
  Arguments:
   FILE  The tree file
  " -> doc

  opt <- docopt(doc)

The first 2 lines are from a previous code, and the rest is about my current work.

My problem is that when I run it,

Finding.R --Threshold 250 INPUT

instead of a warning, error or something coherent, I just get the same script in another window, like nothing happened. I thought it was a problem of my options, but then I tried:

Finding.R --help

And nothing happened.

Could someone shed some light on this? Surely I am doing something wrong, but after looking around in a lot of webpages I couldn't find anything useful.

Upvotes: 1

Views: 523

Answers (1)

zach
zach

Reputation: 31043

There are two potential issues here. The first is that you are probably not invoking R; the second is that you are not doing anything with the options you've parsed. Heres a simple example: note that we invoke Rscript on the first line, and that we print the parsed options on the last.

#!/usr/bin/env Rscript 

library(docopt)
"Usage:
  Finding.R [options]

Options:
--Threshold=<Threshold>       [default: 250]
--output=OUTPUT               [default: out.txt]
--color=<color>               [default: FALSE]
" -> doc

opt <- docopt(doc)
print(opts) 

At the command line:

chmod +x Finding.R
./Finding.R
$`--Threshold`
[1] "250"

$`--output`
[1] "out.txt"

$`--color`
[1] "FALSE"

$Threshold
[1] "250"

$output
[1] "out.txt"

$color
[1] "FALSE"

Upvotes: 1

Related Questions