Learn R Programming

ctypesio (version 0.1.2)

set_na_check: Check for NAs in values before writing

Description

For the majority of binary file formats, there is never the need to store or retrieve an NA value. The default behaviour of this package is to raise an error if any attempt is made to write an NA to file. Set this option to "warn" or "ignore" to modify this.

Usage

set_na_check(con, na_check)

Value

Modified connection object

Arguments

con

Connection object or raw vector. Connection objects can be created with file(), url(), rawConnection() or any of the other many connection creation functions.

na_check

Default NA checking behaviour. One of: 'ignore', 'warn', 'error' Default: 'error'. This default may be over-ridden by specifying the na_check argument when calling individual functions.

ignore

No explicit checks will be made for NA values The underlying R functions (e.g. readBin(), writeBin()) may still do checking.

warn

Explicit checks will be made for NA values before writing. If any NAs are present, then a warning() will be issued.

error

Explicit checks will be made for NA values before writing. If any NAs are present, then an error will be raised.

See Also

Other connection configuration functions: set_bounds_check(), set_endian(), set_eof_check(), set_integer_promotion()

Examples

Run this code
if (FALSE) { # interactive()
# Open a connection and configure it so any attempt to write an NA
# value will cause a warning only (the default behaviour is to raise an error)
con <- rawConnection(raw(), "wb")
con <- set_na_check(con, na_check = "warn")

# This write should work without issues
write_dbl(con, c(1, 2, 3, 4))

# This write will cause a warning
write_dbl(con, c(1, 2, 3, NA))

close(con)
}

Run the code above in your browser using DataLab