Learn R Programming

assertive (version 0.1-7)

assert_is_connection: Is the input a connection?

Description

Checks to see if the input is a (open/incomplete) connection.

Usage

assert_is_connection(x)

  assert_is_open_connection(x, rw = "")

  assert_is_incomplete_connection(x)

  is_connection(x, .xname = get_name_in_parent(x))

  is_open_connection(x, rw = "",
    .xname = get_name_in_parent(x))

  is_incomplete_connection(x,
    .xname = get_name_in_parent(x))

Arguments

x
Input to check.
rw
Read-write status of connection. Passed to isOpen.
.xname
Not intended to be used directly.

Value

  • is_connection checks for objects of class "connection". is_open_connection and is_incomplete_connection wrap isOpen and isIncomplete respectively, providing more information on failure. The assert_* functions return nothing but throw an error if the corresponding is_* function returns FALSE.

See Also

isOpen.

Examples

Run this code
assert_is_connection(stdin())
tcon <- textConnection("txt", "w", local = TRUE)
assert_is_open_connection(tcon)
cat("this has no final newline character", file = tcon)
assert_is_incomplete_connection(tcon)
close(tcon)
#These examples should fail.
assert_is_connection("not a connection")
fcon <- file()
close(fcon)
assert_is_open_connection(fcon)

Run the code above in your browser using DataLab