R: Print Values (original) (raw)

print {base} R Documentation

Description

print prints its argument and returns it invisibly (via[invisible](../../base/help/invisible.html)(x)). It is a generic function which means that new printing methods can be easily added for new [class](../../base/help/class.html)es.

Usage


print(x, ...)

## S3 method for class 'factor'
print(x, quote = FALSE, max.levels = NULL,
      width = getOption("width"), ...)

## S3 method for class 'table'
print(x, digits = getOption("digits"), quote = FALSE,
      na.print = "", zero.print = "0",
      right = is.numeric(x) || is.complex(x),
      justify = "none", ...)

## S3 method for class 'function'
print(x, useSource = TRUE, ...)

Arguments

x an object used to select a method.
... further arguments passed to or from other methods.
quote logical, indicating whether or not strings should be printed with surrounding quotes.
max.levels integer, indicating how many levels should be printed for a factor; if 0, no extra "Levels" line will be printed. The default, NULL, entails choosing max.levelssuch that the levels print on one line of width width.
width only used when max.levels is NULL, see above.
digits minimal number of significant digits, seeprint.default.
na.print character string (or NULL) indicatingNA values in printed output, seeprint.default.
zero.print character specifying how zeros (0) should be printed; for sparse tables, using "." can produce more readable results, similar to printing sparse matrices in Matrix.
right logical, indicating whether or not strings should be right aligned.
justify character indicating if strings should left- or right-justified or left alone, passed to format.
useSource logical indicating if internally stored source should be used for printing when present, e.g., ifoptions(keep.source = TRUE) has been in use.

Details

The default method, [print.default](../../base/help/print.default.html) has its own help page. Use [methods](../../utils/html/methods.html)("print") to get all the methods for theprint generic.

print.factor allows some customization and is used for printing[ordered](../../base/help/ordered.html) factors as well.

print.table for printing [table](../../base/help/table.html)s allows other customization. As of R 3.0.0, it only prints a description in case of a table with 0-extents (this can happen if a classifier has no valid data).

See [noquote](../../base/help/noquote.html) as an example of a class whose main purpose is a specific print method.

References

Chambers, J. M. and Hastie, T. J. (1992)_Statistical Models in S._Wadsworth & Brooks/Cole.

See Also

The default method [print.default](../../base/help/print.default.html), and help for the methods above; further [options](../../base/help/options.html), [noquote](../../base/help/noquote.html).

For more customizable (but cumbersome) printing, see[cat](../../base/help/cat.html), [format](../../base/help/format.html) or also [write](../../base/help/write.html). For a simple prototypical print method, see[.print.via.format](../../tools/help/.print.via.format.html) in package tools.

Examples

require(stats)

ts(1:20)  #-- print is the "Default function" --> print.ts(.) is called
for(i in 1:3) print(1:i)

## Printing of factors
attenu$station ## 117 levels -> 'max.levels' depending on width

## ordered factors: levels  "l1 < l2 < .."
esoph$agegp[1:12]
esoph$alcgp[1:12]

## Printing of sparse (contingency) tables
set.seed(521)
t1 <- round(abs(rt(200, df = 1.8)))
t2 <- round(abs(rt(200, df = 1.4)))
table(t1, t2) # simple
print(table(t1, t2), zero.print = ".") # nicer to read

## same for non-integer "table":
T <- table(t2,t1)
T <- T * (1+round(rlnorm(length(T)))/4)
print(T, zero.print = ".") # quite nicer,
print.table(T[,2:8] * 1e9, digits=3, zero.print = ".")
## still slightly inferior to  Matrix::Matrix(T)  for larger T

## Corner cases with empty extents:
table(1, NA) # < table of extent 1 x 0 >

[Package _base_ version 4.6.0 Index]