如何调试Rscripts从命令行运行?
我目前正在使用该getopt包来传递命令行选项,当出现错误时我很难,我很难:
R(因为脚本需要命令行选项.)有没有人有示例代码并愿意分享?
您可以使用--args将命令行参数传递到交互式shell中,然后将源代码('')传递给脚本.
$ 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')
Run Code Online (Sandbox Code Playgroud)
您现在可以使用旧的browser()函数进行调试.