assertive.files (version 0.0-2)

assert_is_bzfile_connection: Is the input a connection?

Description

Various checks to see if the input is a (particular type of/open/incomplete) connection.

Usage

assert_is_bzfile_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_fifo_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_file_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_gzfile_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_incomplete_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_open_connection(x, rw = "", severity = getOption("assertive.severity", "stop"))
assert_is_pipe_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_readable_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_socket_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_stderr(x, severity = getOption("assertive.severity", "stop"))
assert_is_stdin(x, severity = getOption("assertive.severity", "stop"))
assert_is_stdout(x, severity = getOption("assertive.severity", "stop"))
assert_is_terminal_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_text_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_unz_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_url_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_writable_connection(x, severity = getOption("assertive.severity", "stop"))
assert_is_xzfile_connection(x, severity = getOption("assertive.severity", "stop"))
is_bzfile_connection(x, .xname = get_name_in_parent(x))
is_connection(x, .xname = get_name_in_parent(x))
is_fifo_connection(x, .xname = get_name_in_parent(x))
is_file_connection(x, .xname = get_name_in_parent(x))
is_gzfile_connection(x, .xname = get_name_in_parent(x))
is_incomplete_connection(x, .xname = get_name_in_parent(x))
is_open_connection(x, rw = "", .xname = get_name_in_parent(x))
is_pipe_connection(x, .xname = get_name_in_parent(x))
is_readable_connection(x, .xname = get_name_in_parent(x))
is_socket_connection(x, .xname = get_name_in_parent(x))
is_stderr(x, .xname = get_name_in_parent(x))
is_stdin(x, .xname = get_name_in_parent(x))
is_stdout(x, .xname = get_name_in_parent(x))
is_terminal_connection(x, .xname = get_name_in_parent(x))
is_text_connection(x, .xname = get_name_in_parent(x))
is_unz_connection(x, .xname = get_name_in_parent(x))
is_url_connection(x, .xname = get_name_in_parent(x))
is_writable_connection(x, .xname = get_name_in_parent(x))
is_xzfile_connection(x, .xname = get_name_in_parent(x))

Arguments

x
Input to check.
severity
How severe should the consequences of the assertion be? Either "stop", "warning", "message", or "none".
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. is_readable_connection and is_writable_connection tell you whether the connection is readable from or writable to. is_bzfile_connection, is_fifo_connection, is_file_connection, is_pipe_connection, is_socket_connection, is_stderr, is_stdin, is_stdout, is_text_connection, is_unz_connection, is_url_connection and is_xzfile_connection give more specific tests on the type of connection. 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_terminal_connection(stdin())
assert_is_readable_connection(stdin())
assert_is_open_connection(stdin())
assert_is_stdin(stdin())
# Next line is usually true but, e.g., devtools::run_examples overrides it
assertive.base::dont_stop(assert_is_terminal_connection(stdout()))
assert_is_writable_connection(stdout())
assert_is_open_connection(stdout())
assert_is_stdout(stdout())
assert_is_terminal_connection(stderr())
assert_is_writable_connection(stderr())
assert_is_open_connection(stderr())
assert_is_stderr(stderr())
tcon <- textConnection("txt", "w", local = TRUE)
assert_is_text_connection(tcon)
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.
assertive.base::dont_stop({
  assert_is_connection("not a connection")
  assert_is_readable_connection(stdout())
  assert_is_writable_connection(stdin())
})
## Not run: 
# fcon <- file()
# close(fcon)
# assert_is_open_connection(fcon)
# ## End(Not run)

Run the code above in your browser using DataLab