我已经获得了我的代码,并且正在对下面的代码进行debug(myfun1)。如图所示,我在第13行设置了一个断点。
我的代码如下
myfun1 = function()
{
print("This is myfun1, before calling the myfun2()")
myfun2()
print("This is myfun1, after calling the myfun2()")
print("Does the debugger come back to this point")
}
myfun2 = function()
{
print("This is myfun2, before calling the myfun3()")
myfun3()
print("This is myfun2, after calling the myfun3()")
print("This is the last but one line of myfun2()")
print("This is the last line of myfun2()")
}
myfun3 = function()
{
print("This is myfun3")
}
这些是我用于调试的步骤顺序
See my debug log below
> debugSource('~/Desktop/foo1.R')
> debug(myfun1)
> myfun1()
debugging in: myfun1()
debug at ~/Desktop/foo1.R#2: {
print("This is myfun1, before calling the myfun2()")
myfun2()
print("This is myfun1, after calling the myfun2()")
print("Does the debugger come back to this point")
}
Browse[2]> c
[1] "This is myfun1, before calling the myfun2()"
[1] "This is myfun2, before calling the myfun3()"
[1] "This is myfun3"
Called from: eval(expr, envir, enclos)
Browse[1]> n
debug at ~/Desktop/foo1.R#13: print("This is myfun2, after calling the myfun3()")
Browse[2]> n
[1] "This is myfun2, after calling the myfun3()"
debug at ~/Desktop/foo1.R#14: print("This is the last but one line of myfun2()")
Browse[2]> n
[1] "This is the last but one line of myfun2()"
debug at ~/Desktop/foo1.R#15: print("This is the last line of myfun2()")
Browse[2]> n
[1] "This is the last line of myfun2()"
[1] "This is myfun1, after calling the myfun2()"
[1] "Does the debugger come back to this point"
exiting from: myfun1()
I'm assuming the GUI for RStudio is just a wrapper to the basic debugging functions in R. Setting the breakpoint by clicking on the margin would be equivalent to calling setBreakpoint().
这些函数会trace()
在函数级别上不合时宜地调用。也就是说,跟踪器用启用跟踪的新功能替换了当前功能。并且该替换函数包括一个on.exit
在函数完成时停止跟踪的调用。因此,myfun2
退出后,tacser被禁用,因此您无法在调用myfun2
(is myfun2
)的函数中进行调试。
如果需要在更高级别上进行调试,请在更高级别上设置断点。我不确定是否可以在RStudio GUI中更改调试器,但是如果您自叫,则trace()
可以调用recover()
而不是调用它,browser()
它可以跳转到调用堆栈的不同部分。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句