pp: Pretty print any object.

Description Usage Arguments Details Value See Also Examples

Description

Print values in a way that humans can easily understand.

Usage

1
2
3
4
pp(x = NA, both = FALSE, digits = getOption("pp.digits"),
  signif.digits = getOption("pp.signif.digits"),
  round.digits = getOption("pp.round.digits"),
  format.params = getOption("pp.format.params"))

Arguments

x

An object to print.

both

Show both, the print (unformatted) version and the formatted version of x? FALSE (default) only shows the formatted version.

digits

For x between -1 and 1, this is the same as round.digits. For x outside of the -1 to 1 range, same as signif.digits. NA (default) = ignore.

signif.digits

Integer indicating the number of significant digits to be used, or NA. Ignored if digits or round.digits is not NA. See signif.

round.digits

Integer indicating the number of decimal places to be used, or NA. NA (default) = ignore. Ignored if digits is not NA. See round.

format.params

Parameters passed to format.

Details

At its core, pp is a wrapper around signif, round, and format. Currently, methods are defined for the following classes:

If a “digits” parameter is NA, it is ignored. At most, only one non-NA “digits” parameter is used. Their order of precedence is: digits, round.digits, signif.digits. By default, digits and round.digits are NA.

Value

pp prints x. Do not rely on the value, if any, that pp might return.

See Also

print, signif, round, format, summary.

Other pretty.print.functions: pp.pprop

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
41
42
43
44
45
46
47
48
49
50
51
52
53
## Create a dataset
set.seed(42)
x.big = rnorm(12, mean=1e4, sd=1e3)
x.small = rnorm(12, mean=0, sd=0.5)
name = sample(levels(iris$Species), 12, replace=TRUE)
dd = data.frame(name, x.big, x.small)

pp(dd)			# typical usage
pp(dd, b=TRUE)	# show original and formatted

pp(dd, s=2)		# 2 significant digits
pp(dd, r=2)		# 2 decimal places
# 2 decimal places for small numbers (-1 to 1), 2 significant digits otherwise
pp(dd, d=2)	

pp(dd, s=NA)	# format only, don't round
pp(dd, r=-3)	# round to the nearest thousand

# different signif.digits and round.digits for each column
pp(dd, s=c(NA, NA, 3), r=c(NA, 2, NA))

mm = tcrossprod(x.big, x.small)
pp(mm)	# matrix
pp(qr(mm))	# list

flowers = sample(levels(iris$Species), 1e4, replace=TRUE)
pp(table(flowers))	# table

## Linear Models -- example from lm
ctl <- c(4.17,5.58,5.18,6.11,4.50,4.61,5.17,4.53,5.33,5.14)
trt <- c(4.81,4.17,4.41,3.59,5.87,3.83,6.03,4.89,4.32,4.69)
group <- gl(2, 10, 20, labels = c("Ctl","Trt"))
weight <- c(ctl, trt)
lm.D9 <- lm(weight ~ group)

summary(lm.D9)
pp(lm.D9)	# cleaner output

## Logistic regression
## Create a dataset
set.seed(42)
n = 100
dd = data.frame(x1 = runif(n), x2 = runif(n))
dd = within(dd, {
		x3 = 2 * x1 + x2 + rnorm(n)
		A = factor(cut(x1, 3, FALSE))
		B = factor(cut(x2, 3, FALSE))
		y = factor(cut(x3, 2, FALSE))
	})

gg = glm(y ~ A + B, data = dd, family = "binomial")
summary(gg)	
pp(gg)	# Odds ratios, 95% CI's

prettyprint/prettyprint documentation built on May 25, 2019, 11:26 a.m.