比如这个错误——
seq.default(which(text == "")[1] + 1, length(text), 1)
: 'from' cannot be NA, NaN or infinite
具体锁定的代码是:
get . msg < - function ( path )
{
con < - file ( path , open = "rt" , encoding = "latin1" )
text < - readLines ( con )
msg < - text [ seq ( which ( text == "" ) [ 1 ] + 1 , length ( text ) , 1 ) ]
close ( con )
return ( paste ( msg , collapse = "\n" ) )
}
处理的时候这样——
result = tryCatch ( {
expr
} , warning = function ( w ) {
warning - handler - code
} , error = function ( e ) {
error - handler - code
} , finally = {
cleanup - code
}
get . msg < - function ( path )
{
con < - file ( path , open = "rt" , encoding = "latin1" )
text < - readLines ( con )
msg < - tryCatch ( {
text [ seq ( which ( text == "" ) [ 1 ] + 1 , length ( text ) , 1 ) ]
} , error = function ( e ) {
""
} )
close ( con )
return ( paste ( msg , collapse = "\n" ) )
}