调试小程序/脚本 [英] debugging littler/Rscripts

查看:94
本文介绍了调试小程序/脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调试从命令行运行的 Rscripts

How do I debug Rscripts that are run from the command line?

我目前正在使用 getopt 包传递命令行选项,当有bug时坚果,这很难对我来说:

I am currently using the getopt package to pass command line options, nut when there's a bug, it is hard for me to:


  1. 看看究竟出了什么问题;

  2. R 中进行交互式调试(由于脚本需要命令行选项。)

  1. see what exactly went wrong;
  2. debug interactively in R (since the script expects command line options.)

有没有人有示例代码并愿意分享?

Does anyone have example code and willing to share?

推荐答案

您可以将命令行参数传递到带有--args的交互式shell中,然后将脚本('')。

You could pass your command line arguments into an interactive shell with --args and then source('') the script.

$ R --args -v

R version 2.8.1 (2008-12-22)
Copyright (C) 2008 The R Foundation for Statistical Computing
ISBN 3-900051-07-0

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> require(getopt)
Loading required package: getopt
> opt = getopt(c(
+ 'verbose', 'v', 2, "integer"
+ ));
> opt
$verbose
[1] 1
> source('my_script.R')

您现在可以使用旧的browser()函数进行调试。

You could now use the old browser() function to debug.

这篇关于调试小程序/脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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