gpt4 book ai didi

调试 littler/Rscripts

转载 作者:行者123 更新时间:2023-12-04 13:45:20 27 4
gpt4 key购买 nike

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

我目前正在使用 getopt传递命令行选项的包,当有错误时,我很难:

  • 看看到底出了什么问题;
  • R 中交互式调试(因为脚本需要命令行选项。)

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

    最佳答案

    您可以使用 --args 将命令行参数传递到交互式 shell,然后使用 source('') 脚本。

    $ 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() 函数进行调试。

    关于调试 littler/Rscripts,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1622797/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com