當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


R recover 錯誤後瀏覽

R語言 recover 位於 utils 包(package)。

說明

此函數允許用戶直接瀏覽任何當前活動的函數調用,並且適合作為錯誤選項。表達式 options(error = recover) 將使該選項成為錯誤選項。

用法

recover()

細節

當被召喚時,recover打印當前調用列表,並提示用戶選擇其中之一。標準R browser然後從相應的環境中調用;用戶可以輸入普通的R要在該環境中評估的語言表達式。

在此調用中完成瀏覽後,鍵入 c 以從瀏覽器返回到 recover。輸入另一個幀號以瀏覽更多內容,或輸入 0 退出 recover

使用 recover 在很大程度上取代了 dump.frames 作為錯誤選項,除非您確實想等待查看錯誤。如果在非交互模式下調用recover,則其行為類似於dump.frames。對於涉及大量數據的計算,recover 的優點是不需要複製所有環境即可在其中瀏覽。如果您決定退出交互式調試,請在任何框架中瀏覽時直接調用dump.frames(請參閱示例)。

沒有返回任何有用的東西。但是,您可以直接從函數調用recover,而不是通過示例中顯示的錯誤選項。在這種情況下,在您鍵入 0 退出 recover 後,執行將繼續。

兼容性說明

R recover函數的使用方法與同名的S函數相同;因此,顯示的錯誤選項是指定錯誤操作的兼容方式。然而,實際函數本質上是不相關的,並且與用戶的交互方式完全不同。導航命令updown不存在於R版本;相反,退出瀏覽器並選擇另一個框架。

例子

## Not run: 

options(error = recover) # setting the error option

### Example of interaction

> myFit <- lm(y ~ x, data = xy, weights = w)
Error in lm.wfit(x, y, w, offset = offset, ...) :
        missing or negative weights not allowed

Enter a frame number, or 0 to exit
1:lm(y ~ x, data = xy, weights = w)
2:lm.wfit(x, y, w, offset = offset, ...)
Selection: 2
Called from: eval(expr, envir, enclos)
Browse[1]> objects() # all the objects in this frame
[1] "method" "n"      "ny"     "offset" "tol"    "w"
[7] "x"      "y"
Browse[1]> w
[1] -0.5013844  1.3112515  0.2939348 -0.8983705 -0.1538642
[6] -0.9772989  0.7888790 -0.1919154 -0.3026882
Browse[1]> dump.frames() # save for offline debugging
Browse[1]> c # exit the browser

Enter a frame number, or 0 to exit
1:lm(y ~ x, data = xy, weights = w)
2:lm.wfit(x, y, w, offset = offset, ...)
Selection: 0 # exit recover
>


## End(Not run)

參考

John M. Chambers (1998). Programming with Data; Springer.
See the compatibility note above, however.

也可以看看

browser 有關交互式計算的詳細信息; options用於設置錯誤選項; dump.frames 保存當前環境以供以後調試。

相關用法


注:本文由純淨天空篩選整理自R-devel大神的英文原創作品 Browsing after an Error。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。