printm {lazy.tools}R Documentation

Print multiple objects together with their names
(Compact and better version of Print)

Description

Print multiple objects together with their names
(Compact and better version of Print)

Usage

printm(
  ...,
  .delim. = " ",
  .NAchar. = ".",
  .FILL. = ".^",
  fmt = "",
  .fmt. = "",
  .flag. = " ",
  .printrownum. = 1,
  .lj. = 0,
  .debug. = 0
)

Printm(
  ...,
  .delim. = " ",
  .NAchar. = ".",
  .FILL. = ".^",
  fmt = "",
  .fmt. = "",
  .flag. = " ",
  .printrownum. = 1,
  .lj. = 0,
  .debug. = 0
)

Arguments

...

objects to be printed

.delim.

delimiter string

.NAchar.

a character to indicate NA (One or two single characters, a double byte character, or "" for "na".)

.FILL.

not used.

fmt

a string containing format specification in the form: wid.dig

.fmt.

same as fmt (high precedence)

.flag.

flag options for formatC

.printrownum.

= 0 not to print row numbers for a vector

.lj.

= 1 to left justify character vectors

.debug.

= 1 to print debugging info

Details

This function can print data.frames and list objects together with other objects. In contrast, lazy.tools::Print prints data.frames or lists separately.

Object named fmt cannot be printed unless .fmt. is given.

List objects cannot be formatted.
Data.frames can only be formatted by digits= option which specifies the length of the field. Better use Hmisc::format.df to format data.frames.

When the actual arguments consist of string literals or numbers, they will be printed without names.

The string literals will be printed without names.

The string literals "/" or "\n" indicate new line when they are not the first object of ... .

The native vectors will be printed as column vectors. If a vector has a name, it will be printed as row names. If a vector does not have name, numeric numbers will be printed as row names unless .printrownum.=0 is given.

If the objects contain UTF-8 characters, the result may be misleading due to the bug of print.data.frame method.

fmt or .fmt. contain, if any, formats to be used separated by blanks:
fmt="Width.Digits" will use the following formatC function
formatC( object, format="f", width=Width, digits=Digits )
to format the object.

The first element, separated by blanks, will be applied to the first object of ..., the 2nd element to the 2nd object, and so on.
However, when the first object of ... is a string literal, the first format element will be applied to the 2nd object in ... .

If there are more objects in ... than length(fmt), the last fmt value will be used to fill.

This function can be used with pipe operator.

Use capture.output function, not the return value, to utilize the printed output of this function.

Examples

df1 <- data.frame(x=1:3, y=11:13, row.names=paste("rn",1:3,sep=""))
df1[1,1] <- NA
df2 <- data.frame(x=21:24, y=31:34)
df2[2,2] <- NA
df3 <- data.frame(aa=31:34+.12345, bb=51:54)
df3[2,3] <- NA
mat <- matrix(1:6,3,2, dimnames=list(NULL,c("c1","C2")))
mat[3,2] <- NA
array <- array(1:12, dim=c(3,2,2))
array[1,1,1] <- NA
list <- list(df1,df2)
df <- as.data.frame(rbind(df1,df2))
df[,2] <- as.character(df[,2])
let <- letters[1:4]
names(let) <- toupper(let)
let[2] <- NA
printm( "title",1:3, df1, df2, df3, "/", list, df2+df2, mat, array
        , "newline", "\n", let, letters[1:2], letters[2] )

# vector, matrix and array with format
printm( mat[1,], mat, array, fmt="5.0 5.2 6.3")
# data frame with format: wid part of wid.dig will be used as digits=wid.
printm( df1+0.12345, df1+0.12345, df1+0.12345, fmt="3 4 7")

# no blank line before but a blank line after.
cat("No blank lines.\n")
printm(mat)
cat("One blank line above.\n")
cat("To insert a blank line, use below.\n")
printm("","/", mat+mat)


[Package lazy.tools version 0.1.6 ]