Created attachment 1608 [details]
reproduces the bug. contains non-ascii characters
If I start R as follows:
and then run:
x = paste(readLines('a.html'), collapse = '\n')
con = file(tempfile(), 'w', encoding = 'UTF-8')
R will hang. If I hit control-C I see many identical warnings. In practice these warnings were filling up the hard drive.
I realize this is a corner case and in fact the machine was misconfigured, it should have had a UTF-8-based locale. But the consequences were severe enough (filling up the hard drive) that I report it.
Created attachment 2236 [details]
I think the attached patch solves the issue. With the patch applied, 'writeLines(x, con)' finishes with one warning. The resulting file is the same as without the patch, i.e. truncated at the invalid byte.
Tested with "R Under development (unstable) (2017-03-16 r72358)" on Ubuntu 14.04.5 LTS (iconv is "glibc 2.19") and OS X 10.7.5 (iconv is "GNU libiconv 1.15").
Thanks, fixed in 72361.