Improve the error handling of the #R macro in HTML mode