在R脚本中解析命令行参数 [英] Parsing command line arguments in R scripts

查看:92
本文介绍了在R脚本中解析命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何方便的方法来自动分析传递给R脚本的命令行参数?

Is there any convenient way to automatically parse command line arguments passed to R scripts?

像perl的Getopt::Long一样?

推荐答案

CRAN上有三个软件包:

There are three packages on CRAN:

  • getopt :类似C的getopt行为
  • optparse :受Python的 optparse
  • argparse :命令行可选和位置参数解析器(受Python的 argparse 库启发).此软件包要求将Python解释器与argparsejson(或simplejson)模块一起安装.
  • getopt: C-like getopt behavior
  • optparse: a command line parser inspired by Python's optparse library
  • argparse: a command line optional and positional argument parser (inspired by Python's argparse library). This package requires that a Python interpreter be installed with the argparse and json (or simplejson) modules.

更新:

  • docopt :您可以通过以下方式定义命令行界面:只是以特定格式对其进行描述.它是 docopt.py 的端口.
  • argparser :跨平台命令行参数解析器完全用R编写,没有任何外部依赖关系.该软件包对于Rscript前端很有用,并且有助于将R脚本转换为可执行脚本.
  • minimist :与简约JavaScript库的绑定.该模块实现了乐观主义者的参数解析器的勇气,而没有所有奇特的修饰(没有外部依赖性)
  • optigrab :使用以下命令从命令行解析选项简单,干净的语法.它只需要很少的规范或根本不需要规范,并支持长短选项,GNU,Java或Microsoft风格的语法,动词命令等.
  • docopt: lets you define a command line interface by just giving it a description in the specific format. It is a port a docopt.py.
  • argparser: cross-platform command-line argument parser written purely in R with no external dependencies. This package is useful with the Rscript front-end and facilitates turning an R script into an executable script.
  • minimist: A binding to the minimist JavaScript library. This module implements the guts of optimist's argument parser without all the fanciful decoration (no external dependencies)
  • optigrab: parse options from the command-line using a simple, clean syntax. It requires little or no specification and supports short and long options, GNU-, Java- or Microsoft- style syntaxes, verb commands and more.

这篇关于在R脚本中解析命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆