is_connection: Is the input a connection?

Description Usage Arguments Value Note See Also Examples

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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.

Note

is_incomplete_connection will return false for closed connections, regardless of whether or not the connection ends with a newline character. (isIncomplete throws an error for closed connections.)

See Also

isOpen.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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)

assertive.files documentation built on May 2, 2019, 1:29 p.m.