本文介绍了如何在 R Studio 中显示错误行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在R studio中运行代码后是否可以看到语法错误或运行时错误行号(高亮显示)?

Is it possible to see the syntax error or runtime error line number (highlight also) generated after running the code in R studio?

我搜索了选项但找不到.

I searched the options but couldn't find.

推荐答案

首先看一下?traceback.

有很多方法可以调试 R 代码/脚本.这只是一个例子.

There are many ways to debug R code/script. This is only one example.

在 RStudio 中,从 Debug 下拉菜单选项 On Error,选择 Error Inspector(我认为是)最简单的调试用于查找错误/错误行号的模式.您还可以选择 Break in Code 以显示包含错误的 R 脚本的突出显示行.

In RStudio, from the Debug drop down menu option On Error, choose Error Inspector for (what I think is) the easiest debug mode for finding the line number of an error/bug. You can also choose Break in Code to show the highlighted line of an R script that contains the error.

发生错误时,您可以单击标记为Show TracebackRerun with Debug 的小区域之一.下面的屏幕截图显示了单击显示回溯"的效果(因此现在显示隐藏回溯").它告诉我当 R 尝试调用 sample(第三次调用)时发生了错误.LENGTH 尚未定义.

When the error occurs, you can click either of the small areas marked Show Traceback and Rerun with Debug. The screen shot below shows the effect of clicking "Show Traceback" (hence it now says "Hide Traceback"). It tells me that the error occurred when R attempted to call sample (the third call). LENGTH had not yet been defined.

这篇关于如何在 R Studio 中显示错误行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-02 03:12