Transfer character strings to and from connections, without assuming they are null-terminated on the connection.
readChar(con, nchars, useBytes = FALSE)<p></p><p>writeChar(object, con, nchars = nchar(object, type = "chars"),
eos = "", useBytes = FALSE)</p>
| Parameter | Description |
|---|---|
con |
A connection object, or a character string naming a file, or a raw vector. |
nchars |
integer vector, giving the lengths in characters of (unterminated) character strings to be read or written. Elements must be >= 0 and not NA. |
useBytes |
logical: For readChar, should nchars be regarded as a number of bytes not characters in a multi-byte locale? For writeChar, see writeLines. |
object |
A character vector to be written to the connection, at least as long as nchars. |
eos |
‘end of string’: character string. The terminator to be written after each string, followed by an ASCII nul; use NULL for no terminator at all. |
# NOT RUN {
## test fixed-length strings
zzfil <- tempfile("testchar")
zz <- file(zzfil, "wb")
x <- c("a", "this will be truncated", "abc")
nc <- c(3, 10, 3)
writeChar(x, zz, nc, eos = NULL)
writeChar(x, zz, eos = "\r\n")
close(zz)
zz <- file(zzfil, "rb")
readChar(zz, nc)
readChar(zz, nchar(x)+3) # need to read the terminator explicitly
close(zz)
unlink(zzfil)
# }