Skip to content

Commit

Permalink
version 0.4-13
Browse files Browse the repository at this point in the history
  • Loading branch information
schaffman5 authored and cran-robot committed May 17, 2018
1 parent f01ac37 commit 5b955c5
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 51 deletions.
8 changes: 4 additions & 4 deletions DESCRIPTION
@@ -1,17 +1,17 @@
Package: rtf
Version: 0.4-11
Version: 0.4-13
Depends: R (>= 2.10.1)
Imports: R.oo, R.methodsS3
Suggests: ggplot2, lattice, grid, xtable, gsubfn
Date: 2013-08-22
Date: 2018-05-16
Title: Rich Text Format (RTF) Output
Authors@R: c(person(c("Michael","E."), "Schaffer", role=c("aut", "cre", "cph"), email = "mschaff@gmail.com"))
Description: A set of R functions to output Rich Text Format (RTF) files with high resolution tables and graphics that may be edited with a standard word processor such as Microsoft Word.
License: GPL (>= 2)
LazyLoad: TRUE
Packaged: 2013-11-12 12:21:59 UTC; mschaff
Packaged: 2018-05-17 01:39:48 UTC; mschaff
NeedsCompilation: no
Repository: CRAN
Date/Publication: 2013-11-12 14:19:04
Date/Publication: 2018-05-17 04:16:00 UTC
Author: Michael E. Schaffer [aut, cre, cph]
Maintainer: Michael E. Schaffer <mschaff@gmail.com>
22 changes: 10 additions & 12 deletions MD5
@@ -1,17 +1,17 @@
eab2f611c34479463b255138733b4206 *DESCRIPTION
5d6ee6f3954cb58f7d21960208eaec8d *NAMESPACE
9457c4ccd1a19958bf5bfad76ce2bd66 *NEWS
88d2458021f9406127e3d5d7092418b8 *DESCRIPTION
6015fa85e83b9586bfa2728035def343 *NAMESPACE
4bb517c9079f824be6a8ada45ffb4fa5 *NEWS
c70b4f49da19d10a1caa5eea5a0b1646 *R/000.R
5b3829e46dfdaab40048f81006bc223f *R/999.NonDocumentedObjects.R
e8a3d5d61e56d96501584618f59e23c0 *R/999.package.R
43df9ca89bfd981ea655b4e217c46fd9 *R/forest.plot.R
e852554da9d32f5f05588298494362bc *R/rtf.R
093acfad4a4f867aeec7370383806dc3 *build/vignette.rds
d011ae55f424f023ae6fbef4ff694983 *inst/doc/rtf.R
34575410fff43c3fc819104cda716036 *inst/doc/rtf.Rnw
e87236d58389319d01a7002d26601d5b *inst/doc/rtf.pdf
2c757fd0158d7ad2fbaebe80d6feaebe *R/rtf.R
07b257aa180d1cc189f051b6a4963df1 *build/vignette.rds
6e917732587d97373e4ad04888db419d *inst/doc/rtf.R
cabe9cd967e1bb16eb2d3a06cf4402b2 *inst/doc/rtf.Rnw
055e8dd0ed3a3de76b380facf3855236 *inst/doc/rtf.pdf
3dc27d9397bf3d389a60b73d012e527a *man/Non-documented_objects.Rd
d2e204d8d720b115c3a4d90eecc755fd *man/RTF.Rd
ba105e7432bf356820b2a69b068aa4c8 *man/RTF.Rd
bb6195f3c38920a8d13ab0d3767d8ffa *man/addHeader.RTF.Rd
b263cbecb4eed4461f018f6faea8e3ec *man/addNewLine.RTF.Rd
7b4b105758c9c165f1a3e6a0be7bd86b *man/addPageBreak.RTF.Rd
Expand All @@ -33,6 +33,4 @@ d82b3c397c339f67c982b430523de204 *man/setFontSize.RTF.Rd
215f129af18f2b3cf6900dcd472ef046 *man/startParagraph.RTF.Rd
dcb400c9b1de65af049cf18dd74dbe74 *man/view.RTF.Rd
2273e5f32ab901f9a00e568dd501e175 *tests/tests.R
c49cdb7d09a0185ce0ce71d7ffdf6750 *vignettes/rtf-019.pdf
7480ea252f69ac86fe79b0eb7f3d84f2 *vignettes/rtf-021.pdf
34575410fff43c3fc819104cda716036 *vignettes/rtf.Rnw
cabe9cd967e1bb16eb2d3a06cf4402b2 *vignettes/rtf.Rnw
22 changes: 22 additions & 0 deletions NAMESPACE
@@ -1,3 +1,25 @@
import("R.methodsS3")
import("R.oo")
importFrom("grDevices", "dev.off", "png")
importFrom("graphics", "abline", "arrows", "axTicks", "lines", "par", "plot", "points", "text")
importFrom("utils", "sessionInfo")
exportPattern("^[^\\.]")

S3method(addHeader, RTF)
S3method(addNewLine, RTF)
S3method(addPageBreak, RTF)
S3method(addParagraph, RTF)
S3method(addPlot, RTF)
S3method(addPng, RTF)
S3method(addSessionInfo, RTF)
S3method(addTOC, RTF)
S3method(addTable, RTF)
S3method(addText, RTF)
S3method(addTrellisObject, RTF)
S3method(decreaseIndent, RTF)
S3method(done, RTF)
S3method(endParagraph, RTF)
S3method(increaseIndent, RTF)
S3method(setFontSize, RTF)
S3method(startParagraph, RTF)
S3method(view, RTF)
8 changes: 8 additions & 0 deletions NEWS
@@ -1,3 +1,11 @@
CHANGES IN 0.4-13 (2014-08-07)
-----------------------------
Added explicit imports and exports to resolve CRAN checks.

CHANGES IN 0.4-12 (2014-08-07)
-----------------------------
Added color table.

CHANGES IN 0.4-11 (2013-11-12)
-----------------------------
Changed to author to use Authors@R
Expand Down
57 changes: 54 additions & 3 deletions R/rtf.R
Expand Up @@ -83,6 +83,7 @@
# \seealso{
# @seeclass
# }
#
#*/#########################################################################
setConstructorS3("RTF",
function(file="",width=8.5,height=11,omi=c(1,1,1,1),font.size=10) {
Expand Down Expand Up @@ -144,6 +145,7 @@ setConstructorS3("RTF",
# }
#
# @keyword -internal
#
#*/###########################################################################
setMethodS3("addTable", "RTF", function(this,dat,col.widths=NULL,col.justify=NULL,header.col.justify=NULL,font.size=NULL,row.names=FALSE,NA.string="-", space.before=NULL, space.after=NULL, ...) {
if(is.null(font.size)) {
Expand Down Expand Up @@ -243,6 +245,7 @@ setMethodS3("done", "RTF", function(this, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addTOC", "RTF", function(this,...) {
toc<-"{\\field\\flddirty\\fldedit{\\*\\fldinst TOC f h}{\\fldrslt Update Field (right-click in MS Word) to show Table of Contents}}\\line\\line"
Expand Down Expand Up @@ -284,6 +287,7 @@ setMethodS3("addTOC", "RTF", function(this,...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addHeader", "RTF", function(this, title,subtitle=NULL,font.size=NULL,TOC.level=NULL,...) {
if(is.null(font.size)) {
Expand Down Expand Up @@ -320,6 +324,7 @@ setMethodS3("addHeader", "RTF", function(this, title,subtitle=NULL,font.size=NUL
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addText", "RTF", function(this, ..., bold=FALSE, italic=FALSE) {
text<-paste(... , sep="")
Expand Down Expand Up @@ -355,6 +360,7 @@ setMethodS3("addText", "RTF", function(this, ..., bold=FALSE, italic=FALSE) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addParagraph", "RTF", function(this, ...) {
text<-paste(... , sep="")
Expand Down Expand Up @@ -391,6 +397,7 @@ setMethodS3("addParagraph", "RTF", function(this, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("startParagraph", "RTF", function(this, ...) {
this$.rtf <- paste(this$.rtf,.start.paragraph(indent=this$.indent),sep="")
Expand Down Expand Up @@ -419,6 +426,7 @@ setMethodS3("startParagraph", "RTF", function(this, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("endParagraph", "RTF", function(this, ...) {
this$.rtf <- paste(this$.rtf,.end.paragraph(),sep="")
Expand Down Expand Up @@ -456,6 +464,7 @@ setMethodS3("endParagraph", "RTF", function(this, ...) {
# }
#
# @keyword -internal
#
#*/###########################################################################
setMethodS3("addPageBreak", "RTF", function(this, width=8.5,height=11,omi=c(1,1,1,1), ...) {
this$.rtf <- paste(this$.rtf,.add.page.break(width=width,height=height,omi=omi),sep="")
Expand Down Expand Up @@ -488,6 +497,7 @@ setMethodS3("addPageBreak", "RTF", function(this, width=8.5,height=11,omi=c(1,1,
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addNewLine", "RTF", function(this, n=1, ...) {
this$.rtf <- paste(this$.rtf,.add.newline(n=n,font.size=this$.font.size),sep="")
Expand Down Expand Up @@ -516,6 +526,7 @@ setMethodS3("addNewLine", "RTF", function(this, n=1, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("increaseIndent", "RTF", function(this, ...) {
this$.indent <- this$.indent + 720 # 1/2" increments
Expand Down Expand Up @@ -544,6 +555,7 @@ setMethodS3("increaseIndent", "RTF", function(this, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("decreaseIndent", "RTF", function(this, ...) {
this$.indent <- max(0,this$.indent - 720) # 1/2" increments
Expand Down Expand Up @@ -573,6 +585,7 @@ setMethodS3("decreaseIndent", "RTF", function(this, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("setFontSize", "RTF", function(this, font.size, ...) {
this$.font.size <- font.size
Expand Down Expand Up @@ -622,6 +635,7 @@ setMethodS3("setFontSize", "RTF", function(this, font.size, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addPlot", "RTF", function(this,plot.fun=plot.fun,width=3.0,height=0.3,res=300, ...) {
if(!is.null(this$.font.size)) {
Expand Down Expand Up @@ -668,6 +682,7 @@ setMethodS3("addPlot", "RTF", function(this,plot.fun=plot.fun,width=3.0,height=0
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addPng", "RTF", function(this,file,width=3.0,height=0.3, ...) {
if(!is.null(this$.font.size)) {
Expand Down Expand Up @@ -729,6 +744,7 @@ setMethodS3("addPng", "RTF", function(this,file,width=3.0,height=0.3, ...) {
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addTrellisObject", "RTF", function(this,trellis.object,width=3.0,height=0.3,res=300, rotate=NULL, ...) {
tmp.file<-tempfile("temp_rtf_trellis")
Expand Down Expand Up @@ -773,6 +789,7 @@ setMethodS3("addTrellisObject", "RTF", function(this,trellis.object,width=3.0,he
# }
#
# @keyword -internal
#
#*/#########################################################################
setMethodS3("addSessionInfo", "RTF", function(this, locale = TRUE, ...) {

Expand Down Expand Up @@ -841,12 +858,12 @@ setMethodS3("addSessionInfo", "RTF", function(this, locale = TRUE, ...) {
######################################################################################

.start.rtf<-function(width=8.5,height=11,omi=c(1,1,1,1)) {
paste("{\\rtf1\\ansi\n\\deff",.add.font.table(),.add.paper.size(width=width,height=height),"\n",.add.page.margins(omi),"\n",.add.page.numbers(),"\n",sep="")
paste("{\\rtf1\\ansi\n\\deff",.add.font.table(),.add.color.table(),.add.paper.size(width=width,height=height),"\n",.add.page.margins(omi),"\n",.add.page.numbers(),"\n",sep="")
}

.add.font.table<-function() {
fonts<-character()
fonts[1]<-"{\\f1\\fswiss\\fcharset0 Helvetica;}"
fonts[1]<-"{\\f1\\fswiss\\fcharset0 Helvetica;}" # default
fonts[2]<-"{\\f2\\ffroman\\charset0\\fprg2 Times New Roman;}"
fonts[3]<-"{\\f3\\ffswiss\\charset0\\fprg2 Arial;}"
fonts[4]<-"{\\f4\\fftech\\charset0\\fprg2 Symbol;}"
Expand All @@ -855,6 +872,16 @@ setMethodS3("addSessionInfo", "RTF", function(this, locale = TRUE, ...) {
paste("{\\fonttbl",paste(fonts,collapse="\n"),"}",sep="\n")
}

.add.color.table<-function() {
colors<-character()
colors[1]<-"{\\red0\\green0\\blue0;}" # default
colors[2]<-"{\\red255\\green0\\blue0;}"
colors[3]<-"{\\red0\\green255\\blue0;}"
colors[4]<-"{\\red0\\green0\\blue255;}"

paste("{\\colortbl",paste(colors,collapse="\n"),"}",sep="\n")
}

.add.page.numbers<-function() {
paste("\\titlepg\\headery720\\footery720","{\\footer {\\pard\\qc\\fi0\\li0 \\f2\\fs20 \\field{\\fldinst{page}} \\par}}",sep="\n")
}
Expand Down Expand Up @@ -1503,4 +1530,28 @@ setMethodS3("addSessionInfo", "RTF", function(this, locale = TRUE, ...) {
decimal[i] <- sum(digits * 16^((length(digits)-1):0))
}
return(decimal)
}
}



# Functions for pivoting data tables
# this is especially useful for pivoting data frames created with ddply.
# Additional options for including gaps between repeated categories
#
#
# tab<-cast(stats, Marker + Visit + TRT ~ stat)
# split.cols<-c("Marker","Visit")
#
# removedups<-function(x){ x[which(as.character(x) == c(tail(as.character(x),-1),NA))+1]<-NA; x }
# removedups_previous<-function(x,y){ x[ setdiff(which(as.character(x) == c(tail(as.character(x),-1),NA))+1,which(!is.na(y))) ]<-NA; x }
#
# tab[,split.cols[1]]<-removedups(tab[,split.cols[1]])
# for(i in 2:length(split.cols)) {
# tab[,split.cols[i]]<-removedups_previous(tab[,split.cols[i]],tab[,split.cols[i-1]])
# }
#
# # Insert section breaks
# idx<-order( c( 1:nrow(tab), which(apply(!is.na(tab[,split.cols]), 1, any))-0.5 )) # break at previous row
# idx[which(idx>nrow(tab))]<-NA
# tab<-tab[idx,]
# colnames(tab)<-c("Marker","Visit","Trt","N","Mean Change From Baseline","Diff. Estimate (95CI)","P")
Binary file modified build/vignette.rds
Binary file not shown.

0 comments on commit 5b955c5

Please sign in to comment.