I think the errors you are seeing are actually parse exceptions (ParseException) and evaluation exceptions (EvaluationException).
In the example of
x = (-1)!
a ParseException is thrown with:
````"Line: 1 Error: unexpected '!'"``` which is fully expected.
In the full example, I believe that your pure R code looks something like this:
warnings <- file('warningsFile.txt', open = 'wt')
sink(warnings, type ='message')
In this case, for me, an EvaluationException is thrown with the message.
"""Error in close.connection(warnings) : cannot close 'message' sink connection"""
Those are actual R errors being converted to exceptions by the REngine and are appropriate. There may be an issue with how the embedded R instance deals with sink, but I think that's outside the scope of those exceptions.