Is it possible to see the syntax error or runtime error line number (highlight also) generated after running the code in R studio?
是否可以在R studio中运行代码后看到语法错误或运行时错误行号(也可以突出显示)?
I searched the options but couldn't find.
我搜索了选项但找不到。
1 个解决方案
#1
8
First, have a look at ?traceback
.
首先,看看?追溯。
There are many ways to debug R code/script. This is only one example.
有很多方法可以调试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.
在RStudio中,从Debug下拉菜单选项On Error,选择Error Inspector(我认为是)最简单的调试模式,用于查找错误/错误的行号。您还可以选择Break in Code以显示包含错误的R脚本的突出显示行。
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.
发生错误时,您可以单击标记为Show Traceback和Rerun with Debug的小区域中的任何一个。下面的屏幕截图显示了点击“Show Traceback”的效果(因此它现在显示为“Hide Traceback”)。它告诉我当R试图调用sample(第三次调用)时发生错误。 LENGTH尚未确定。
#1
8
First, have a look at ?traceback
.
首先,看看?追溯。
There are many ways to debug R code/script. This is only one example.
有很多方法可以调试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.
在RStudio中,从Debug下拉菜单选项On Error,选择Error Inspector(我认为是)最简单的调试模式,用于查找错误/错误的行号。您还可以选择Break in Code以显示包含错误的R脚本的突出显示行。
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.
发生错误时,您可以单击标记为Show Traceback和Rerun with Debug的小区域中的任何一个。下面的屏幕截图显示了点击“Show Traceback”的效果(因此它现在显示为“Hide Traceback”)。它告诉我当R试图调用sample(第三次调用)时发生错误。 LENGTH尚未确定。