zz <- textConnection("foo", "w")
#> Error in writeChar("abc", zz) : 'write' not enabled for this connection
The same thing happens if one tries to use `R_WriteConnection()` on a output textConnection. The underlying cause seems to be that textConnections never change the `write` function in the connection object from `null_write` (See src/main/connections.c#L500).
The same behavior occurs with `stdout()` with the same underlying cause (write function not defined).
#> Error in writeChar("test", stdout()) :
#> 'write' not enabled for this connection
the 2nd paragraph in 'Details' says :
These functions are intended to be used with binary-mode
connections. If ‘con’ is a character string, the functions call
‘file’ to obtain a binary-mode file connection which is opened for
the duration of the function call.
so it seems this is all according to documentation.
Maybe we should mention "binary" or "binary-mode" already in the description of the 'con' argument ?
OTOH, I think I also had been surprised in the past by the fact that only binary connections were supported... given that there is also writeBin().
Then, if you look more closely, the reference explains how the two are different and why both functionalities are needed.
Still, I agree that it would seem natural to *expect* that writeChar() would work for a text connection (and then also for other "text like" connections).
I let others chime in, not being a connection expert.
I'd tend to set this to "WISHLIST" status and be happy to accept patches that enable writing to more connections than currently.