{"id":180368,"date":"2024-05-08T20:33:59","date_gmt":"2024-05-08T12:33:59","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/180368.html"},"modified":"2024-05-08T20:34:09","modified_gmt":"2024-05-08T12:34:09","slug":"%e7%94%a8r%e8%af%ad%e8%a8%80%e7%bc%96%e7%a8%8b%e6%8a%a5%e9%94%99%ef%bc%8c%e5%a6%82%e4%bd%95%e8%bf%94%e5%9b%9e%e9%94%99%e8%af%af%e6%89%80%e5%9c%a8%e8%a1%8c%e5%8f%b7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/180368.html","title":{"rendered":"\u7528R\u8bed\u8a00\u7f16\u7a0b\u62a5\u9519\uff0c\u5982\u4f55\u8fd4\u56de\u9519\u8bef\u6240\u5728\u884c\u53f7"},"content":{"rendered":"<p style=\"text-align:center\"><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/27065634\/2a180009-a8ee-489f-ab9e-f572b67f3a8e.webp\" alt=\"\u7528R\u8bed\u8a00\u7f16\u7a0b\u62a5\u9519\uff0c\u5982\u4f55\u8fd4\u56de\u9519\u8bef\u6240\u5728\u884c\u53f7\" \/><\/p>\n<p><p><strong>\u7528R\u8bed\u8a00\u7f16\u7a0b\u65f6\u51fa\u73b0\u9519\u8bef\u3001\u8b66\u544a\u6216\u5f02\u5e38<\/strong>\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5feb\u901f\u5b9a\u4f4d\u5230\u9519\u8bef\u6240\u5728\u7684\u884c\u53f7\uff1a<strong>options(error = recover)\u3001traceback()\u3001browser()\u51fd\u6570\u3001debug()\u51fd\u6570\u3002<\/strong> \u5176\u4e2d\uff0c<strong>options(error = recover)<\/strong> \u53ef\u4ee5\u5728\u9519\u8bef\u53d1\u751f\u540e\u63d0\u4f9b\u4e00\u4e2a\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\u4f9b\u7528\u6237\u9009\u62e9\u8fdb\u5165\u54ea\u4e00\u4e2a\u51fd\u6570\u7684\u73af\u5883\u8fdb\u884c\u8c03\u8bd5\uff0c\u4ece\u800c\u627e\u5230\u9519\u8bef\u7684\u5177\u4f53\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><p><strong>options(error = recover)<\/strong> \u51fd\u6570\u901a\u8fc7\u8bbe\u7f6eR\u7684\u9519\u8bef\u5904\u7406\u9009\u9879\uff0c\u4f7f\u5f97\u5728\u51fa\u73b0\u9519\u8bef\u65f6R\u4f1a\u663e\u793a\u51fa\u9519\u51fd\u6570\u7684\u8c03\u7528\u5806\u6808\uff0c\u5e76\u5141\u8bb8\u7528\u6237\u6d4f\u89c8\u8c03\u7528\u5806\u6808\u7684\u5404\u4e2a\u51fd\u6570\uff0c\u4ee5\u4fbf\u67e5\u770b\u5728\u54ea\u4e00\u6b65\u54ea\u4e00\u884c\u51fa\u73b0\u95ee\u9898\u3002\u8fd9\u662f\u4e00\u79cd\u975e\u5e38\u76f4\u89c2\u7684\u8c03\u8bd5\u65b9\u6cd5\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u5904\u7406\u590d\u6742\u7684\u7a0b\u5e8f\u9519\u8bef\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u8bbe\u7f6e\u9519\u8bef\u9009\u9879<\/h3>\n<\/p>\n<p><p><strong>\u5728R\u811a\u672c\u7684\u5f00\u59cb\u90e8\u5206\u6dfb\u52a0\u9519\u8bef\u9009\u9879\u7684\u8bbe\u7f6e<\/strong>\uff0c\u53ef\u4ee5\u786e\u4fdd\u7a0b\u5e8f\u5728\u6267\u884c\u8fc7\u7a0b\u4e2d\u4e00\u65e6\u51fa\u73b0\u9519\u8bef\uff0c\u5c31\u4f1a\u89e6\u53d1\u9519\u8bef\u5904\u7406\u673a\u5236\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-r\">options(error = recover)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528traceback()<\/h3>\n<\/p>\n<p><p>\u5f53\u7a0b\u5e8f\u9519\u8bef\u5bfc\u81f4R\u4f1a\u8bdd\u5d29\u6e83\u65f6\uff0c\u53ef\u4ee5\u5728\u63a7\u5236\u53f0\u4f7f\u7528 <strong>traceback()<\/strong> \u51fd\u6570\u56de\u987e\u9519\u8bef\u53d1\u751f\u524d\u7684\u51fd\u6570\u8c03\u7528\u5e8f\u5217\u3002\u6b64\u51fd\u6570\u5c06\u6253\u5370\u51fa\u9519\u8bef\u53d1\u751f\u65f6\u7684\u8c03\u7528\u6808\u4fe1\u606f\u3002<strong>traceback()<\/strong> \u662f\u5728\u9519\u8bef\u4e4b\u540e\u8c03\u7528\u7684\uff0c\u4e0d\u9700\u8981\u9884\u5148\u8bbe\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u63a2\u7a76\u9519\u8bef<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528 <strong>browser()<\/strong> \u51fd\u6570\u8ba9\u4ee3\u7801\u5728\u7279\u5b9a\u7684\u884c\u53f7\u8fdb\u5165\u6d4f\u89c8\u6a21\u5f0f\uff0c\u5728\u8fd9\u79cd\u6a21\u5f0f\u4e0b\u53ef\u4ee5\u67e5\u770b\u53d8\u91cf\u7684\u5f53\u524d\u72b6\u6001\uff0c\u9010\u884c\u6267\u884c\u4ee3\u7801\uff0c\u975e\u5e38\u9002\u5408\u4e8e\u9010\u6b65\u8c03\u8bd5\u548c\u76d1\u63a7\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u6fc0\u6d3b\u8c03\u8bd5\u6a21\u5f0f<\/h3>\n<\/p>\n<p><p>\u901a\u8fc7 <strong>debug()<\/strong> \u51fd\u6570\u53ef\u4ee5\u5c06\u6307\u5b9a\u7684\u51fd\u6570\u6807\u8bb0\u4e3a\u8c03\u8bd5\u72b6\u6001\uff0c\u5728\u8be5\u51fd\u6570\u88ab\u8c03\u7528\u65f6\u4f1a\u81ea\u52a8\u8fdb\u5165\u6d4f\u89c8\u5668\u73af\u5883\uff0c\u4fbf\u4e8e\u68c0\u67e5\u548c\u8ffd\u8e2a\u51fd\u6570\u5185\u7684\u4ee3\u7801\u548c\u53d8\u91cf\u3002\u5982\u679c\u80fd\u591f\u786e\u5b9a\u662f\u5728\u67d0\u4e2a\u81ea\u5b9a\u4e49\u51fd\u6570\u4e2d\u51fa\u73b0\u4e86\u95ee\u9898\uff0c\u4f7f\u7528 <strong>debug()<\/strong> \u53ef\u4ee5\u975e\u5e38\u9ad8\u6548\u5730\u8fdb\u884c\u95ee\u9898\u8ffd\u8e2a\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-r\">debug(myFunction)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><strong>\u8fd0\u7528\u8fd9\u4e9b\u5de5\u5177\u548c\u6280\u5de7<\/strong>\uff0c\u901a\u5e38\u80fd\u6709\u6548\u627e\u5230R\u4ee3\u7801\u4e2d\u7684\u9519\u8bef\u53d1\u751f\u4f4d\u7f6e\uff0c<strong>\u5927\u5927\u7b80\u5316\u8c03\u8bd5\u8fc7\u7a0b<\/strong>\u3002\u63a5\u4e0b\u6765\uff0c\u6211\u4eec\u4f1a\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u5229\u7528\u8fd9\u4e9b\u65b9\u6cd5\u5728R\u7f16\u7a0b\u4e2d\u8fdb\u884c\u9519\u8bef\u5b9a\u4f4d\u4e0e\u5904\u7406\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>1. R\u8bed\u8a00\u7f16\u7a0b\u65f6\u51fa\u9519\u4e86\uff0c\u5982\u4f55\u786e\u5b9a\u51fa\u9519\u7684\u4ee3\u7801\u6240\u5728\u7684\u884c\u53f7\uff1f<\/strong><\/p>\n<p>\u5f53R\u8bed\u8a00\u4ee3\u7801\u62a5\u9519\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u6765\u786e\u5b9a\u9519\u8bef\u6240\u5728\u7684\u884c\u53f7\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u67e5\u770b\u62a5\u9519\u4fe1\u606f\uff1aR\u8bed\u8a00\u4f1a\u5728\u62a5\u9519\u4fe1\u606f\u4e2d\u7ed9\u51fa\u4e00\u4e9b\u63d0\u793a\uff0c\u544a\u8bc9\u4f60\u9519\u8bef\u53d1\u751f\u7684\u4f4d\u7f6e\u6216\u539f\u56e0\u3002<\/li>\n<li>\u5176\u6b21\uff0c\u68c0\u67e5\u62a5\u9519\u4fe1\u606f\u4e2d\u7684\u51fd\u6570\u8c03\u7528\u6808\uff1a\u62a5\u9519\u4fe1\u606f\u4e2d\u4f1a\u663e\u793a\u51fd\u6570\u7684\u8c03\u7528\u6808\u4fe1\u606f\uff0c\u901a\u8fc7\u67e5\u770b\u8c03\u7528\u6808\u53ef\u4ee5\u63a8\u65ad\u51fa\u9519\u8bef\u53d1\u751f\u7684\u4f4d\u7f6e\u3002<\/li>\n<li>\u7136\u540e\uff0c\u5f53\u62a5\u9519\u4fe1\u606f\u4e2d\u6ca1\u6709\u660e\u786e\u6307\u51fa\u9519\u8bef\u4f4d\u7f6e\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>traceback()<\/code>\u51fd\u6570\u83b7\u53d6\u5f53\u524d\u9519\u8bef\u7684\u8c03\u7528\u6808\uff0c\u4ece\u800c\u786e\u5b9a\u9519\u8bef\u6240\u5728\u7684\u884c\u53f7\u3002<\/li>\n<\/ul>\n<p><strong>2. \u5728R\u8bed\u8a00\u7f16\u7a0b\u4e2d\uff0c\u5982\u4f55\u901a\u8fc7\u62a5\u9519\u4fe1\u606f\u5b9a\u4f4d\u9519\u8bef\u7684\u5177\u4f53\u884c\u53f7\uff1f<\/strong><\/p>\n<p>\u5f53R\u8bed\u8a00\u4ee3\u7801\u62a5\u9519\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u6765\u5b9a\u4f4d\u9519\u8bef\u7684\u5177\u4f53\u884c\u53f7\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u67e5\u770b\u62a5\u9519\u4fe1\u606f\u4e2d\u7684\u51fd\u6570\u540d\u79f0\u548c\u9519\u8bef\u63cf\u8ff0\uff1a\u62a5\u9519\u4fe1\u606f\u4e2d\u4f1a\u663e\u793a\u89e6\u53d1\u9519\u8bef\u7684\u51fd\u6570\u540d\u79f0\u548c\u76f8\u5173\u7684\u9519\u8bef\u63cf\u8ff0\uff0c\u6839\u636e\u8fd9\u4e9b\u4fe1\u606f\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u5b9a\u4f4d\u5230\u76f8\u5e94\u7684\u51fd\u6570\u8c03\u7528\u3002<\/li>\n<li>\u7136\u540e\uff0c\u4f7f\u7528<code>debug()<\/code>\u51fd\u6570\u5bf9\u53d1\u751f\u9519\u8bef\u7684\u51fd\u6570\u8fdb\u884c\u8c03\u8bd5\uff1a\u5728\u51fd\u6570\u5b9a\u4e49\u7684\u884c\u4e4b\u524d\u8c03\u7528<code>debug()<\/code>\u51fd\u6570\uff0c\u7136\u540e\u518d\u6b21\u8fd0\u884c\u4ee3\u7801\u3002\u5f53\u4ee3\u7801\u6267\u884c\u5230\u8c03\u8bd5\u70b9\u65f6\u4f1a\u505c\u4e0b\u6765\uff0c\u8fd9\u65f6\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\u884c\u8fdb\u884c\u53d8\u91cf\u67e5\u770b\u548c\u5355\u6b65\u8c03\u8bd5\uff0c\u4ece\u800c\u5b9a\u4f4d\u5230\u9519\u8bef\u53d1\u751f\u7684\u884c\u53f7\u3002<\/li>\n<\/ul>\n<p><strong>3. R\u8bed\u8a00\u4e2d\uff0c\u9047\u5230\u62a5\u9519\u5982\u4f55\u8ffd\u8e2a\u9519\u8bef\u6240\u5728\u7684\u884c\u53f7\uff1f<\/strong><\/p>\n<p>\u5f53R\u8bed\u8a00\u4ee3\u7801\u62a5\u9519\u65f6\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8ffd\u8e2a\u9519\u8bef\u6240\u5728\u7684\u884c\u53f7\uff1a<\/p>\n<ul>\n<li>\u9996\u5148\uff0c\u68c0\u67e5\u62a5\u9519\u4fe1\u606f\u4e2d\u7684\u9519\u8bef\u63cf\u8ff0\uff1a\u62a5\u9519\u4fe1\u606f\u4e2d\u4f1a\u63d0\u4f9b\u9519\u8bef\u53d1\u751f\u7684\u5177\u4f53\u63cf\u8ff0\uff0c\u6839\u636e\u8fd9\u4e9b\u63cf\u8ff0\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u627e\u5230\u53ef\u80fd\u51fa\u9519\u7684\u4f4d\u7f6e\u3002<\/li>\n<li>\u7136\u540e\uff0c\u901a\u8fc7\u9010\u884c\u6267\u884c\u7684\u65b9\u5f0f\u5b9a\u4f4d\u9519\u8bef\uff1a\u5c06\u4ee3\u7801\u5206\u4e3a\u591a\u4e2a\u90e8\u5206\uff0c\u9010\u4e2a\u90e8\u5206\u6267\u884c\uff0c\u76f4\u5230\u62a5\u9519\u53d1\u751f\u4e3a\u6b62\u3002\u8fd9\u6837\u53ef\u4ee5\u9010\u6b65\u7f29\u5c0f\u51fa\u9519\u7684\u8303\u56f4\uff0c\u6700\u7ec8\u5b9a\u4f4d\u5230\u9519\u8bef\u53d1\u751f\u7684\u884c\u53f7\u3002<\/li>\n<li>\u6700\u540e\uff0c\u4f7f\u7528\u65ad\u70b9\u8c03\u8bd5\u6280\u672f\uff1a\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u5f53\u4ee3\u7801\u6267\u884c\u5230\u65ad\u70b9\u65f6\u4f1a\u6682\u505c\u6267\u884c\uff0c\u53ef\u4ee5\u901a\u8fc7\u68c0\u67e5\u53d8\u91cf\u503c\u548c\u9010\u884c\u6267\u884c\u6765\u5b9a\u4f4d\u9519\u8bef\u6240\u5728\u7684\u5177\u4f53\u884c\u53f7\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u7528R\u8bed\u8a00\u7f16\u7a0b\u65f6\u51fa\u73b0\u9519\u8bef\u3001\u8b66\u544a\u6216\u5f02\u5e38\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5feb\u901f\u5b9a\u4f4d\u5230\u9519\u8bef\u6240\u5728\u7684\u884c\u53f7\uff1aoptions(error = [&hellip;]","protected":false},"author":3,"featured_media":180392,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180368"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=180368"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/180368\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/180392"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=180368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=180368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=180368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}