dprint.data.frame: Print Table to Graphics Device (dprint)

Description Usage Arguments Details Author(s) Examples

Description

Prints tabular data to the graphics device by translating an R object to a tabular presentation.

Usage

1
2
3
4
5
6
7
8
## S3 method for class 'data.frame'
dprint(data, fmla = NULL, label = NULL, group = NULL,
  regx = NA, style = NULL, main = NA, footnote = NA,
  dtype = "rgraphics", pg.dim = NULL, margins = NULL,
  showmargins = FALSE, row.hl = NULL, fit.width = FALSE,
  fit.height = FALSE, fit = FALSE, newpage = FALSE, center.horz = FALSE,
  center.vert = FALSE, center = FALSE, f.hdr = NULL, f.ftr = NULL,
  pagenum = NULL, lastcall = NULL)

Arguments

data

An object of class found among methods(dprint)

fmla

An object of class “formula”. Formula interface is used to describe the properties of tabular data to be printed from the data object.

label

Character vector of length 1 used to reference the name of column containing row labels. Optional to fmla. Set to NULL to when using fmla or when no row labels exist. Default value is NULL.

group

Character vector of length 1 used to reference the name of column containing grouping of row labels. Optional to fmla. Set to NULL to when using fmla or when no row labels exist. Default value is NULL.

regx

Character vector of length 1 used to provide regular expression(s) to remove unwanted text displayed from original column names (e.g. merge applied with .x and .y appended to duplicate column names)

style

Style sheet object used to define font and other settings of the table. See style and frmt

main

Table title defined by character vector of length 1. String will be placed on top of table

footnote

Footnote defined by character vector finite length. The text will be printed immediately underneath the tabular presentation. Each position in the vector will force a new line break.

dtype

Named references to preset pg.dim settings. Graphics device type referred to by names, sets default page settings. Device types, currently available "rdevice", "portrait", "landscape" which sets pg.dim to c(8,8), (11, 8.5) and (8.5, 11)

pg.dim

A vector of c(height,width) units used to describe the dimensions of a custom page and over ride dtype. When printing to a multiple page pdf with custom dimensions, dtype should be set to some character other than "rdevice" (i.e. "custom") because dev.new() will be used to start a new window instead of grid.text().

margins

A numerical vector of the form c(bottom, left, top, right) which gives the margin size specified in inches. Other declarations assume a constant for all margins or c(top/bottom,left/right)

showmargins

Boolean, displays margins on R device. Useful for tinkering with presentation

row.hl

Conditional highligh row highlight object. See row.hl

fit.width

Boolean. If TRUE, forces the table to fit the table horizontally within the pg.dim and margins. Exactly fits when vector formats are used, approximation otherwise.

fit.height

Boolean. If TRUE, forces the table to fit the table vertically within the pg.dim and margins. Exactly fits when vector formats are used, approximation otherwise.

fit

Boolean. If TRUE, forces the table to fit both horizontally and vertically within the pg.dim and margins.

newpage

Boolean. If TRUE, when the presentation of the table runs out of space on the current page, within the pg.dim and margins, a new page will automatically be started. Designed for multiple page pdf reports.

center.horz

Boolean, If TRUE, center table horizontally

center.vert

Boolean, If TRUE, center table vertically. Only available for single table.

center

Boolean, If TRUE, center both vertically and horizontally. Does not consider the fit.* parameters

f.hdr

Pass a function for printing header. See examples and hdr

f.ftr

Pass a function for printing footer. See examples and ftr

pagenum

Starting page number, will override page number from last call

lastcall

Object returned from last call from dprint. Can use this as reference for where a second table should be presented on the same device as the previous call. dprint continues printing to device with fixed separation between tables

Details

The available method functions for dprint are given by methods(dprint).

Formula Interface: Operator Definitions

Formula Interface: Embedded Functions

“\n” can be used in main or footnote paramters or embedded function Rn() to force additional line breaks

Author(s)

Carlin Brickner

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
 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
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
### Generate Sample Data Structures ###
# Generate some example data frames
table1   <- rdesc(4, 5)        # Numeric
table1f <- rdesc(4, 5, rnd=TRUE) # Rounded and pretty format so values are character
table1a <- table1; table1b<-table1;
table1a$group2 <- 1; table1b$group2 <- 2;
table2 <- rbind(table1a, table1b)
table2a <- table2; table2b<-table2
table2a$group3 <- "Zebra"; table2b$group3 <- "Elephant";
table3 <- rbind(table2a, table2b)
# Create style object
CBs <- style(frmt.bdy=frmt(fontfamily="HersheySans"), frmt.tbl=frmt(bty="o", lwd=1),
            frmt.col=frmt(fontfamily="HersheySans", bg="khaki",fontface="bold",lwd=2,bty="_"),
            frmt.grp=frmt(fontfamily="HersheySans",bg="khaki", fontface="bold"),
            frmt.main=frmt(fontfamily="HersheySans", fontface="bold", fontsize=12),
            frmt.ftn=frmt(fontfamily="HersheySans"),
            justify="right")

# dev.new()# All variables, no group or label
dprint(~., data=table1f)
dev.off()
# dev.new() # Spanning,  group level, and apply control and treatments to hierchaies on right
dprint(group+level~Control:(Mean1 + Median1 + Variance1) +
 Treatment:(Mean2 + Median2 + Variance2) + p.value, data=table1f)
dev.off()
# dev.new(); #Illegal Names, remove expression
dprint(group+level~`This is a Control`:(Mean1 + Median1 + Variance1) +
 Treatment.y:(Mean2 + Median2 + Variance2), data=table1f, regx="1|2|.y")
dev.off()
# dev.new(); #Illegal Names, no group label
dprint( ~ `This is a Control`:(Mean1 + Median1 + Variance1) + 
Treatment.y:(Mean2 + Median2 + Variance2), data=table1f, regx="1|2|.y")
# dev.new(); # all on rhs with exception of p.value
dev.off()
dprint(group+level~.-p.value, data=table1f)
dev.off()
## Not run: 
# dev.new();
dprint(fmla=group+level~., data=table1)
dev.off()
# dev.new()
dprint(fmla=group+level~Rn(round(Mean1, 2), "Mean Trt")+Rn(round(Variance1,2), "Variance"), 
data=table1)
dev.off()
# dev.new()
dprint(group+level~Rn(round(Mean1, 2), "Mean Trt")+
Variance1+Rn(round(I((Mean1+Mean2)/2),2), "Average of Averages"), data=table1, main="Don't Do this")
dev.off()
# dev.new()
dprint(level~.|group2, data=table2)
dev.off()
# dev.new();
dprint(level~Mean1+Median2|group2, data=table2, main="Descriptives")
dev.off()
# dev.new(); # Spanning, embedded fuctions, and conditional
dprint(group+level~Treatment:Rn(paste(round(Mean1, 2),"(", round(Variance1, 2),")"),
 "Mean Trt (Std)")|group2, data=table2)
dev.off()
# dev.new(); # Spanning, embedded fuctions, and conditional
dprint(~Treatment:Rn(paste(round(Mean1, 2),"(", round(Variance1, 2),")"), 
"Mean Trt (Std)")|group2, data=table2)
# dev.new(); # Spanning, embedded fuctions, and conditional
dev.off()
dprint(~Treatment:(Rn(paste(round(Mean1, 2),"(", round(Variance1, 2),")"), "Mean Trt (Std)")+
Rn(round(Median1,2), "Median"))|group2, data=table2)
dev.off()
# dev.new()
dprint(~Treatment:Rn(paste(round(Mean1, 2),"(", round(Variance1, 2),")"), "Mean Trt (Std)")+
Control:Rn(paste(round(Mean2, 2),"(", round(Variance2, 2),")"), "Mean Trt (Std)")|group2,
 data=table2)
dev.off()

f1 <- group+level~Treatment:Rn(Fc(Mean1, Variance1), "Mean (Std)")+
Control:Rn(Fc(Mean2, Variance2), "Mean (Std)") + Rn(round(p.value,2), "P-value")
# dev.new()
dprint(fmla=f1, data=table1,margins=.2, main="Justify Center")
dev.off()
# dev.new()
dprint(fmla=f1, data=table1,margins=.2, main="Justify Right", 
style=style(justify="right", frmt.tbl=frmt(bty="o")))
dev.off()
# dev.new()
dprint(fmla=f1, data=table1,margins=.2, main="Justify Left", 
style=style(justify="left", frmt.tbl=frmt(bty="o")))
dev.off()

 h <- expression(hdr("Test Header", 
 pagelayout.obj=pagelayout(dtype="rgraphics", margins=c(1, .5))))
 f <- expression(ftr("R Package tabulaR", 
 pagelayout.obj=pagelayout(dtype="rgraphics", margins=c(1.25, 1, 1.25,1)), 
 pagenum=eval.parent(pagenum, 1)))
 # dev.new()
 dprint(fmla=f1, data=table1,margins=c(1.25, 1, 1.25,1), showmargins=TRUE, main="Table Left",
            style=style(justify="left", frmt.tbl=frmt(bty="o"), 
           frmt.bdy=frmt(linespace=1.5, bty="X")),
            f.hdr = h, f.ftr=f, pagenum=1)
dev.off()

# dev.new()
 dprint(fmla=f1, data=table1,margins=c(1.25, 1, 1.25,1), showmargins=TRUE, main="Table Left",
            style=CBs,
            f.hdr = h, f.ftr=f, pagenum=1)
 dev.new()
 by_var_f1 <- level~Mean1+Median1|group
 by_var_f2 <- level~Mean1+Median1|group+group2
# If main is default (null) than do not print titles
 dprint(fmla=by_var_f1, data=table2)
 dev.off()
# dev.new()
# When a title is defined, and only one conditional variable is defined, just print the values
# concatenated to the text
dprint(fmla=by_var_f1, data=table2,main=" ")
dev.off()
# dev.new()
# When more than one conditional variable, concatenate the variable name and the
# current combination of values
dprint(fmla=by_var_f2, data=table2,main="Descriptives for: ")    

## End(Not run)

Example output

$cord1
[1] 0.2 6.8

$cord2
                  
6.033333 3.258333 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
5.908667 2.611667 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
4.935000 2.611667 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
3.780667 3.249889 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
5.305667 2.771222 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                    
10.608222  2.771222 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
2.711889 2.771222 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
4.778778 2.616653 

$pagenum
[1] 2

null device 
          1 
$cord1
                  
0.200000 3.159444 

$cord2
                      
11.1431111 -0.2311111 

$pagenum
[1] 2

null device 
          1 
$cord1
                  
0.200000 3.004875 

$cord2
                    
 3.967444 -0.540250 

$pagenum
[1] 2

null device 
          1 
$cord1
                  
0.200000 2.361667 

$cord2
                    
 2.316889 -1.826667 

$pagenum
[1] 2

null device 
          1 
$cord1
                  
0.200000 2.999889 

$cord2
                      
 1.1625556 -0.5502222 

$pagenum
[1] 2

null device 
          1 
$cord1
                  
0.200000 2.999889 

$cord2
                      
 1.7676667 -0.5502222 

$pagenum
[1] 2

null device 
          1 
$cord1
                  
0.200000 2.999889 

$cord2
                      
 2.1251111 -0.5502222 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
3.612333 2.457097 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
                  
3.612333 2.457097 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 0.2 6.8

$cord2
       3          
3.612333 2.457097 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 1.00 5.75

$cord2
       3          
4.412333 2.384375 

$pagenum
[1] 2

null device 
          1 
$cord1
[1] 1.00 5.75

$cord2
                  
4.448760 1.425779 

$pagenum
[1] 2

dev.new(): using pdf(file="Rplots1.pdf")
$cord1
            
0.200 0.665 

$cord2
                    
 3.902556 -1.130000 

$pagenum
[1] 2

pdf 
  2 
$cord1
                    
0.2000000 0.2012917 

$cord2
                    
 3.902556 -1.748278 

$pagenum
[1] 2

null device 
          1 
$cord1
                    
 0.200000 -3.012542 

$cord2
                    
 3.902556 -4.164333 

$pagenum
[1] 2

dprint documentation built on May 2, 2019, 10:14 a.m.