{"id":23611636,"url":"https://github.com/jmbarbone/scribe","last_synced_at":"2025-05-12T19:07:57.327Z","repository":{"id":65681886,"uuid":"535950693","full_name":"jmbarbone/scribe","owner":"jmbarbone","description":"Argument parsing for Rscript","archived":false,"fork":false,"pushed_at":"2024-06-07T04:30:41.000Z","size":4390,"stargazers_count":3,"open_issues_count":5,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-12T19:07:44.455Z","etag":null,"topics":["cli","r","r-package","rscript"],"latest_commit_sha":null,"homepage":"https://jmbarbone.github.io/scribe/","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/jmbarbone.png","metadata":{"files":{"readme":"README.Rmd","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-09-13T03:58:06.000Z","updated_at":"2024-10-15T14:40:58.000Z","dependencies_parsed_at":"2023-02-18T13:00:30.197Z","dependency_job_id":"eecf02cb-9d2f-4f6e-9ebe-79388228b085","html_url":"https://github.com/jmbarbone/scribe","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmbarbone%2Fscribe","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmbarbone%2Fscribe/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmbarbone%2Fscribe/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jmbarbone%2Fscribe/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jmbarbone","download_url":"https://codeload.github.com/jmbarbone/scribe/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253805861,"owners_count":21967053,"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":["cli","r","r-package","rscript"],"created_at":"2024-12-27T16:17:12.249Z","updated_at":"2025-05-12T19:07:57.253Z","avatar_url":"https://github.com/jmbarbone.png","language":"R","funding_links":[],"categories":[],"sub_categories":[],"readme":"---\noutput: github_document\neditor_options: \n  chunk_output_type: console\n---\n\n\u003c!-- README.md is generated from README.Rmd. Please edit that file --\u003e\n\n```{r setup}\n#| include: false\nknitr::opts_chunk$set(\n  collapse = TRUE,\n  comment = \"#\u003e\",\n  fig.path = \"man/figures/README-\",\n  out.width = \"100%\"\n)\n```\n\n# scribe\n\n\u003c!-- badges: start --\u003e\n[![R-CMD-check](https://github.com/jmbarbone/scribe/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/jmbarbone/scribe/actions/workflows/R-CMD-check.yaml)\n[![Codecov test coverage](https://codecov.io/gh/jmbarbone/scribe/branch/main/graph/badge.svg)](https://app.codecov.io/gh/jmbarbone/scribe?branch=main)\n\u003c!-- badges: end --\u003e\n\nThe goal of scribe is to provide a detailed argument parser for `Rscript`.\nThis package contains no dependencies outside of `base` and `methods`.\nThe core functions utilize `ReferenceClasses` under the hood.\n\n```{r library}\nlibrary(scribe)\n```\n\nInstall `{scribe}` from CRAN with:\n\n``` r\ninstall.packages(\"scribe\")\n```\n\nAlternatively, you can install the development version of `{scribe}` [GitHub](https://github.com/) with:\n\n```\n# install.packages(\"devtools\")\ndevtools::install_github(\"jmbarbone/scribe\")\n```\n\nYou can enter command arguments as a vector to test out the behavior.\nArguments can be added to the ``r class(command_args())`` class (here as `ca`).\nDefault behavior tries to parse objects but additional control can be taken.\n\n```{r example-simple}\nca \u003c- command_args(c(\"-a\", \"1\", \"-b\", \"2\"))\nca$add_argument(\"-a\")\nca$add_argument(\"-b\")\nargs \u003c- ca$parse()\n\nstr(args$a + args$b)\n```\n\nControl\n\n```{r example-controls}\n# don't convert numbers\nca \u003c- command_args(c(\"-a\", \"1\", \"-b\", \"1.0\"))\nca$add_argument(\"-a\", convert = as.character)\nca$add_argument(\"-b\", convert = as.character)\nca$parse()\n\n# convert numbers to integers\nca \u003c- command_args(c(\"verbose\", \"1\", \"1.5\", \"1.9\"))\nca$add_argument(\"verbose\", action = \"flag\")\nca$add_argument(\"...\", convert = as.integer)\nca$parse()\n\n# use functions for more control\nca \u003c- command_args(c(\"verbose\", \"12-9-2022\", \"12-10-2022\"))\nca$add_argument(\"verbose\", action = \"flag\")\nca$add_argument(\"...\", convert = function(i) as.Date(i, \"%m-%d-%Y\"))\nca$parse()\n```\n\nYou'll probably use `{scribe}` within small scripts that can be called from your favorite terminal.\nThe example below uses a function to call this file, but if it is added to your `PATH` you'd be able to call it directly:\n\n``` bash\nr-file -a 1 -b 9\n```\n\n```{r example-script}\nlines \u003c- \"\n#! /usr/bin/env -S Rscript --vanilla \n\nlibrary(scribe)\nca \u003c- scribe::command_args()\nca$add_argument('-a', default = 1)\nca$add_argument('-b', default = 2)\nargs \u003c- ca$parse()\n\nfoo \u003c- function(a, b, ...) {\n  a + b\n}\n\ndo.call(foo, args)\n\"\n\nfile \u003c- tempfile()\nwriteLines(lines, file)\n\nrscript \u003c- function(x, args = character()) {\n  args \u003c- c(\"--vanilla\", x, args)\n  res \u003c- system2(\"Rscript\", args, stdout = TRUE)\n  writeLines(res)\n}\n\nrscript(file)\nrscript(file, \"-a 0\")\nrscript(file, \"-a 0 -b 10\")\n```\n\n```{r remove}\n#| include: false\nfile.remove(file)\n```\n\n## Examples\n\nI've been using `{scribe}` for some personal scripts.\nBelow is a short list of some examples (mostly in my [`jmb`](https://github.com/jmbarbone/jmb) repo):\n\n- [pak](https://github.com/jmbarbone/jmb/blob/main/bin/pak): call [`{pak}`](https://pak.r-lib.org/) from your terminal\n- [update-r-pkgs](https://github.com/jmbarbone/jmb/blob/main/bin/update-r-pkgs): update old R packages\n- [todos](https://github.com/jmbarbone/jmb/blob/main/bin/todos): calls [`mark::todos()`](https://jmbarbone.github.io/mark/reference/todos.html)\n- [fixmes](https://github.com/jmbarbone/jmb/blob/main/bin/fixmes): calls [`mark::fixmes()`](https://jmbarbone.github.io/mark/reference/todos.html)\n\n## Other packages\n\nThis isn't the first package.\nMost contain other dependencies, some even in different languages (e.g., `python`).\n\n- [`{argparse}`](https://github.com/trevorld/r-argparse)\n- [`{optparse}`](https://github.com/trevorld/r-optparse)\n- [`{getopt}`](https://github.com/trevorld/r-getopt)\n- [`{minimist}`](https://github.com/jeroen/minimist) (CRAN archived)\n- [`{optigrab}`](https://github.com/decisionpatterns/optigrab)\n- [`{docopt}`](https://github.com/docopt/docopt.R)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmbarbone%2Fscribe","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjmbarbone%2Fscribe","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjmbarbone%2Fscribe/lists"}