我已经获取了我的代码并且正在对下面的代码进行调试(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")
}
这些是我用于调试的步骤序列
请参阅下面的调试日志
> 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()
答案 0 :(得分:1)
我假设RStudio的GUI只是R中基本调试功能的包装器。通过单击边距来设置断点等同于调用setBreakpoint().
这些函数不合时宜地调用trace()
,它在函数级别上运行。也就是说,跟踪器用一个能够跟踪的新函数替换当前函数;并且该替换函数包括on.exit
调用以在函数完成时停止跟踪。因此,在myfun2
退出后,tacser会被禁用,因此您无法在调用myfun2
(myfun2
)的函数内部进行调试。
如果需要在更高级别进行调试,请将断点设置为更高级别。我不确定您是否可以在RStudio GUI中更改调试器,但如果您自己致电trace()
,则可以拨打recover()
而不是browser()
,这样您就可以跳转到调用堆栈的不同部分。