R语言用tryCatch进行错误处理,现在的问题是,你要锁定那段内容。
比如你要锁定这样一个内容:msg <- text[seq(which(text == "")[1] + 1, length(text), 1)]
那就可以这么写:
msg <- tryCatch({
text[seq(which(text == "")[1] + 1, length(text), 1)] }, error = function(e) { "" })
附上tryCatch的使用方法——
result = tryCatch ( {
expr
} , warning = function ( w ) {
warning - handler - code
} , error = function ( e ) {
error - handler - code
} , finally = {
cleanup - code
}