I would like to know how can I check if a html is available. If it is not, I would like to control the return to avoid stop the script by error.
Ex:
arq <- readLines("www.pageerror.com.br")
print(arq)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
An alternative is
try()– it is simpler to work with thantrycatch()but isn’t as featureful. You might also need to suppress warnings as R will report that it can’t resolve the address.You want something like this in your script:
The
silent = TRUEbit suppresses the reporting of errors (if you leave this at the defaultFALSE, then R will report the error but not abort the script). We wrap the potentially error-raising function call intry(...., silent = TRUE), withsuppressWarnings()being used to suppress the warnings. Then we test the class of the returned objectarqand if it inherits from class"try-error"we know the page could not be retrieved and issue a message indicating so. Otherwise we can printarq.