messages: Pretty print messages convenience

Description Usage Arguments Details Value Note TODO Examples

Description

This function uses is a convenience function for writing error, warning, and message statements. p_note is an alias for p_statement.

p0ff is a convenience printer for function and for internals, used to avoid using flush.console().

pf is used for force the printing of passed objects within nested functions such as loops, applys, and data.tables. No changes are made to the passed object.

%P%{} Is a convenient pipe function used for interactive programming. When it is desired to print all the rows of a table-like object, one can merely add %P%{} to the end of the expression, which avoids the necessity of wrapping the expression with print(..., nrows = Inf).

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
capture(x)

p_msg(..., envir = parent.frame())

p_warn(..., envir = parent.frame())

p_stop(..., parent_call = NULL, envir = parent.frame())

p_statement(..., envir = parent.frame())

p_note(..., envir = parent.frame())

p0ff(..., sep = "", collapse = NULL)

pf(...)

x %P% P

Arguments

...

Accepts any mix of character strings and objects containing character vectors.

parent_call

Defaults to NULL, but may be override to a character vector of length one which will show up as the name of the parent function from which the error originates.

sep

a character string to separate the terms. Not NA_character_.

collapse

Defaults to " " but you can override it if you desire.

Details

Any list provided to input x will be unlisted and collapsed in the same way that any character vector would be collapsed. This function relies on sprintf and paste. Removes all consecutive (extra) spaces and removes /r returns and /n newlines as well. To keep newlines, you need to input then as /newline or /new, as /n by itself will be deleted.

Value

A character vector (1) collapsed, (2) comma separated, and (3) having each item in single quotes. Additionally text will be concatenated.

Note

The regular expression work could be much better, this is a to-do at some point. to-do: p_paste (p_note or p_statement could be renamed instead?) would be a character vector output a person could use, possibly, but would not accept non-character class objects.

TODO

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
32
33
34
35
36
37
38
39
40
## Not run: 
DT <- data.table(1:10, LETTERS[1:10])
DF <- data.frame(v1 = 1:10, v2 = LETTERS[1:10])
l <- list(one = "1", two = "2")
char <- "this is a message with a return:\newline yay"
fac <- factor("this is a message too")
mat <- matrix(c(1:10, 10:1), nrow = 10)
TBmisc:::capture(DT)
TBmisc:::capture(DF)
TBmisc:::capture(l)
TBmisc:::capture(char)
TBmisc:::capture(fac)
TBmisc:::capture(mat)
p_msg("DT:", DT, char)
p_msg("this is a note", list("hi", "bye", NULL))
p_warn("DT:", DT, char)
testit <- function() p_warn("DT:", DT, char)
testit()
p_statement("This is just a plain note", DT, char)
test_stop <- function() p_stop("DT:", DT, char)
test_stop()
p_stop("DT:", DT, char)
p_stop("This is really bad!", DT, char)
p_stop("This is really bad!", DT, char, parent_call = "bad_fn")

require(TBmisc)
packages <- c("xtable", "knitr", "data.table", "ggplot2", "zoo", "xlsx",
"RODBC")
pkg_loader(packages, verbose = TRUE)
capture(packages)

## End(Not run)



for (i in seq(5)) p0ff(i)
sapply(seq(10), pf)
DT <- data.table(x = seq(500), y = seq(500))
print(DT) # data.table prints the convenient top-5 bottom-5 by default.
DT %P%{} # simple print pipe for infinite nrows.

JamesDalrymple/wccmh documentation built on May 7, 2019, 10:20 a.m.