{"id":28726869,"url":"https://github.com/docopt/docopt.r","last_synced_at":"2025-06-15T13:09:26.531Z","repository":{"id":11633793,"uuid":"14135771","full_name":"docopt/docopt.R","owner":"docopt","description":"Command-line interface description language for R (http://docopt.org)","archived":false,"fork":false,"pushed_at":"2025-03-25T21:02:55.000Z","size":249,"stargazers_count":214,"open_issues_count":19,"forks_count":17,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-28T21:36:08.718Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"R","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/docopt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-11-05T08:18:55.000Z","updated_at":"2025-03-27T22:56:51.000Z","dependencies_parsed_at":"2022-09-06T09:50:30.712Z","dependency_job_id":null,"html_url":"https://github.com/docopt/docopt.R","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/docopt/docopt.R","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.R","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.R/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.R/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.R/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/docopt","download_url":"https://codeload.github.com/docopt/docopt.R/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/docopt%2Fdocopt.R/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259981475,"owners_count":22941149,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-15T13:09:25.700Z","updated_at":"2025-06-15T13:09:26.521Z","avatar_url":"https://github.com/docopt.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![version](https://www.r-pkg.org/badges/version/docopt)](https://cran.r-project.org/package=docopt)\n![downloads](https://cranlogs.r-pkg.org/badges/docopt)\n[![R build status](https://github.com/docopt/docopt.R/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/docopt/docopt.R/actions/workflows/R-CMD-check.yaml)\n[![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/docopt/docopt.R?branch=master\u0026svg=true)](https://ci.appveyor.com/project/docopt/docopt.R)\n[![status](https://tinyverse.netlify.com/badge/docopt)](https://CRAN.R-project.org/package=docopt)\n\n\n# docopt\n\n`docopt` helps you to:\n\n- define an interface for your command-line application, and\n- automatically generate a parser for it.\n\nR package `docopt` is an implementation of [docopt](http://docopt.org) in the R programming language.\nSee my presentation on the [useR! 2014](http://www.slideshare.net/EdwindeJonge1/docopt-user2014) for more details.\n\nFor more information see [docopt.org](http://docopt.org)\n\nTo try docopt in your browser visit [try.docopt.org](http://try.docopt.org/)\n\n\n## Installation\n\nThe easiest way to get `docopt` is to install from \n[CRAN](https://cran.r-project.org/web/packages/docopt/index.html):\n\n```R\ninstall.packages(\"docopt\")\nlibrary(docopt)\n```\n### Development version\n\nThe latest version of `docopt` can be installed from GitHub using \n[devtools](https://github.com/r-lib/devtools):\n\n```R\nlibrary(devtools)  # make sure to have devtools 1.4!\ninstall_github(\"docopt/docopt.R\")\n```\n\n\n## Testing\n\nIt is tested against the tests defined for the reference implementation.\nIt passes most tests. It currently fails tests that \n\n- count arguments: `my_prog.R -v -v` should return `list(v=2)`\n\nThe tests can be run using `devtools::test()` and can be found in \"tests\" directory.\n\n```R\nlibrary(devtools)\ndevtools::test()\n```\n\n\n## Usage\n\n`docopt` uses the description of the command-line interface (i.e. help message docstring) \nto parse command-line arguments.\n\n```R\n'Naval Fate.\n\nUsage:\n  naval_fate.R ship new \u003cname\u003e...\n  naval_fate.R ship \u003cname\u003e move \u003cx\u003e \u003cy\u003e [--speed=\u003ckn\u003e]\n  naval_fate.R ship shoot \u003cx\u003e \u003cy\u003e\n  naval_fate.R mine (set|remove) \u003cx\u003e \u003cy\u003e [--moored | --drifting]\n  naval_fate.R (-h | --help)\n  naval_fate.R --version\n\nOptions:\n  -h --help     Show this screen.\n  --version     Show version.\n  --speed=\u003ckn\u003e  Speed in knots [default: 10].\n  --moored      Moored (anchored) mine.\n  --drifting    Drifting mine.\n\n' -\u003e doc\n\nlibrary(docopt)\narguments \u003c- docopt(doc, version = 'Naval Fate 2.0')\nprint(arguments)\n```\n\nThe option parser is generated based on the docstring above that is passed to `docopt` function. \n`docopt` parses the usage pattern (`\"Usage: ...\"`) and option descriptions \n(lines starting with dash `\"-\"`) and ensures that the program invocation matches the \nusage pattern; it parses options, arguments and commands based on that. \nThe basic idea is that *a good help message has all necessary information in it to make a parser*.\n\nTo execute your command-line application you need to provide path to command-line executable file\n(i.e. `naval_fate.R` in our case) and provide relevant command-line `arguments/options/commands`.\n\nFor example\n\n* To print command-line application help message:\n\n```\n$ Rscript path/to/naval_fate.R --help\nNaval Fate.\n\nUsage:\n  naval_fate.R ship new \u003cname\u003e...\n  naval_fate.R ship \u003cname\u003e move \u003cx\u003e \u003cy\u003e [--speed=\u003ckn\u003e]\n  naval_fate.R ship shoot \u003cx\u003e \u003cy\u003e\n  naval_fate.R mine (set|remove) \u003cx\u003e \u003cy\u003e [--moored | --drifting]\n  naval_fate.R (-h | --help)\n  naval_fate.R --version\n\nOptions:\n  -h --help     Show this screen.\n  --version     Show version.\n  --speed=\u003ckn\u003e  Speed in knots [default: 10].\n  --moored      Moored (anchored) mine.\n  --drifting    Drifting mine.\n```\n\n* To print command-line application version information:\n\n```\n$ Rscript path/to/naval_fate.R --version\nNaval Fate 2.0\n```\n\n* `docopt` function returns a list of command-line parameters and their \n  corresponding values that can be accessed via `$` within your command-line \n  application.\n\n```\n$ Rscript path/to/naval_fate.R ship Guardian move 10 50 --speed=20\nList of 23\n $ --help    : logi FALSE\n $ --version : logi FALSE\n $ --speed   : chr \"20\"\n $ --moored  : logi FALSE\n $ --drifting: logi FALSE\n $ ship      : logi TRUE\n $ new       : logi FALSE\n $ \u003cname\u003e    : chr \"Guardian\"\n $ move      : logi TRUE\n $ \u003cx\u003e       : chr \"10\"\n $ \u003cy\u003e       : chr \"50\"\n $ shoot     : logi FALSE\n $ mine      : logi FALSE\n $ set       : logi FALSE\n $ remove    : logi FALSE\n $ help      : logi FALSE\n $ version   : logi FALSE\n $ speed     : chr \"20\"\n $ moored    : logi FALSE\n $ drifting  : logi FALSE\n $ name      : chr \"Guardian\"\n $ x         : chr \"10\"\n $ y         : chr \"50\"\n```\n\n* In case if provided command-line parameters are inconsistent with the \n  `\"Usage: ...\"` pattern the error message will be printed along with\n  usage pattern examples.\n\n```\n$ Rscript path/to/naval_fate.R ship mine\nError: \n usage: naval_fate.R ship new \u003cname\u003e...\n  \n usage: naval_fate.R ship \u003cname\u003e move \u003cx\u003e \u003cy\u003e [--speed=\u003ckn\u003e]\n  \n usage: naval_fate.R ship shoot \u003cx\u003e \u003cy\u003e\n  \n usage: naval_fate.R mine (set|remove) \u003cx\u003e \u003cy\u003e [--moored | --drifting]\n  \n usage: naval_fate.R (-h | --help)\n  \n usage: naval_fate.R --version\nExecution halted\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.r","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdocopt%2Fdocopt.r","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdocopt%2Fdocopt.r/lists"}