View source: R/connection-config.R
set_eof_check | R Documentation |
When the end-of-file is reached and values are requested from the connection,
how should a read
call check and react?
set_eof_check(con, eof_check = "error")
con |
Connection object or raw vector. Connection objects can be
created with |
eof_check |
Default EOF checking behaviour. One of: 'ignore', 'warn', 'error' Default: 'error'.
|
Note: R's readBin()
does not necessarily react when the end-of-file
is reached, and in many situations all that will happen is that fewer
data values will be returned than what was requested.
By setting this option on the connection, work is done to check the count of returned values after every call to try and detect when the end-of-file has been reached.
Modified connection object
Other connection configuration functions:
set_bounds_check()
,
set_endian()
,
set_integer_promotion()
,
set_na_check()
# Open a connection and configure it so reading past the end-of-file
# ignored, and operations simply return fewer values than requested
con <- rawConnection(as.raw(1:8), "rb")
con <- set_eof_check(con, eof_check = "ignore")
# There are only 8 bytes in the connection.
# Attempting to read 12 bytes will reach the end of the file.
# Because "eof_check" has been set to "ignore", there will just be
# silent truncation of the data
read_uint8(con, n = 12)
# The connection can be configured to raise an error or warning
# when EOF is reached
con <- set_eof_check(con, eof_check = "warn")
read_uint8(con, n = 12)
close(con)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.