问题描述
当出现错误消息时,我想继续运行用eval
和parse
函数执行的R代码。考虑以下示例:
my_code <- "x <- 5 # Some code as string
mean[x]
y <- 10"
eval(parse(text = my_code)) # Apply eval & parse
# Error in mean[x] : object of type 'closure' is not subsettable
y # This should return the value 10
# Error: object 'y' not found
存储在字符串my_code
中的R代码应执行到字符串结尾,即使之前发生错误也是如此。
This thread解释了如何跳过R中的错误。但是,由于必须用eval
和{{1}执行我的R代码,因此我无法应用此线程中显示的解决方案。 }。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)