如何从一开始就逐步执行R脚本? [英] How to step through an R script from the beginning?

查看:119
本文介绍了如何从一开始就逐步执行R脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想逐步执行R脚本。在搜索如何执行此操作时,我看到了调试命令,但这似乎仅适用于函数。该脚本没有任何功能。

I want to step through an R script. I saw the "debug" command while searching for how to do this but that seems to only apply to functions. This script doesn't have any functions.

browser命令看起来很有希望,所以我将 browser()作为脚本的第一行,但是没有当我运行它时似乎什么也没做。

The "browser" command looked promising so I put "browser()" as the first line of my script but it didn't seem to do anything when I ran it.

如何使脚本在第一行暂停,以便我可以逐步执行?

How do I get the script to pause on the first line so I can step through it?

推荐答案

我正在绞尽脑汁,试图在RStudio的IDE版本0.98.1102中解决这个问题(逐步执行一个没有特定函数调用的脚本)。

I was racking my brain trying to figure this out (stepping through a script without a specific function to call) in RStudio's IDE Version 0.98.1102.

在RStudio中创建新脚本的解决方案:


  1. 创建新的R脚本( ctrl + shift + n

  2. 在文件中输入代码

  3. 设置断点,通过

    • a)在代码行编号的左侧单击要设置断点的位置(红色点)或

    • b)将 browser()添加到要设置代码行的代码行断点

  1. Create a new R script (ctrl+shift+n)
  2. Enter code in the file
  3. Set a break point by
    • a) clicking left of the code line number where you want to set a break point (red dot) or
    • b) adding browser() to the code line where you want to set a break point

  • a)选中保存时的源框(在 Source 窗口),然后保存文件,

  • b)单击 Source 窗口右上方的 Source 按钮,

  • c)输入 debugSource(< yourfilename>) + enter 控制台

  • d)中输入 ctrl + shift + s

  • a) checking the Source on Save box (above the Source window) and then saving the file,
  • b) clicking the Source button at the top-right of the Source window,
  • c) entering debugSource("<yourfilename>") + enter in the Console, or
  • d) entering ctrl+shift+s

有关在RStudio中进行调试的更多步骤,请参见此帮助文件
(日期为2015年4月23日12:59)。

For more steps on debugging in RStudio, see this help file (dated April 23, 2015 12:59).

这篇关于如何从一开始就逐步执行R脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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