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

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

问题描述

有没有什么方便的方法可以自动解析传递给 R 脚本的命令行参数?

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

类似于 perl 的 Getopt::Long?

Something like perl's 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:绑定到 minimist JavaScript 库.这个模块实现了 optimist 参数解析器的核心,没有任何花哨的装饰(没有外部依赖)
  • optirab:使用命令行解析选项一个简单、干净的语法.它几乎不需要任何规范,支持短选项和长选项、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天全站免登陆