Skip to content

Commit

Permalink
version 0.4-4
Browse files Browse the repository at this point in the history
  • Loading branch information
schaffman5 authored and gaborcsardi committed Apr 11, 2012
1 parent 6a1336f commit d4d5a77
Show file tree
Hide file tree
Showing 11 changed files with 156 additions and 31 deletions.
14 changes: 8 additions & 6 deletions DESCRIPTION
@@ -1,15 +1,17 @@
Package: rtf
Version: 0.4-3
Date: 2011-10-03
Version: 0.4-4
Date: 2012-04-11
Title: Rich Text Format (RTF) Output
Author: Michael E. Schaffer
Maintainer: Michael E. Schaffer <mschaff@gmail.com>
Depends: R (>= 2.10.1), R.oo (>= 1.7.4)
Depends: R (>= 2.10.1), R.oo (>= 1.7.4), gsubfn
Imports: methods
Suggests: lattice, grid
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.
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: BSD
LazyLoad: TRUE
Date/Publication: 2011-11-02 17:26:40
Packaged: 2011-10-30 15:41:29 UTC; mschaff
Packaged: 2012-05-12 15:00:24 UTC; mschaff
Date/Publication: 2012-05-12 15:37:04
Repository: CRAN
19 changes: 10 additions & 9 deletions MD5
@@ -1,19 +1,20 @@
a2b81d04f8f3b52a8e52adf14dcd30fe *DESCRIPTION
072676d3772366d17415302ac8eb3271 *DESCRIPTION
6a15a3469549adaf6fee5ac9c2d05a93 *LICENSE
012592abf4b40a8d741b299df2ded05a *NAMESPACE
8795199f0a00f4ee29a2fe6e664c74b5 *NEWS
f890a6cd328b6d5b7329b59ca53cd47f *R/000.R
40e9627b336738df97fbcf1218934f9a *R/999.NonDocumentedObjects.R
d38df017f2b1a04783fcb6698beef67c *NEWS
c31072f884b26035ad9269fd9674af99 *R/000.R
a6884a76e59afa78da41dc36c5801159 *R/999.NonDocumentedObjects.R
e8a3d5d61e56d96501584618f59e23c0 *R/999.package.R
57a165421cc7bd4f4c12dde2178f05de *R/forest.plot.R
d7d895f0bd14452aa4130f6245c6e386 *R/rtf.R
363e08e49496a0954cf87c1f8d4dd60d *man/Non-documented_objects.Rd
63f3a830e802aa6dcd5a158c657ebc9d *man/RTF.Rd
b4df9b103dd9be02846011dd715b07d2 *R/rtf.R
1ccfa61dde62cbd43016578a7a54f36f *man/Non-documented_objects.Rd
85b7381d77d3bcd36044a80ea25ffa98 *man/RTF.Rd
886727132906e6c2a63db3c4ae0f589e *man/addHeader.RTF.Rd
fb35cefcded0a44e28c42e7f9fb6ddb3 *man/addNewLine.RTF.Rd
e86a7edb843a38b01ad6acd03a906133 *man/addPageBreak.RTF.Rd
172142af3efdbb7cd86824f5de43dedc *man/addParagraph.RTF.Rd
6bde274eaa5545742e8d47fa18597282 *man/addPlot.RTF.Rd
2fdbb7bd318602ca0aeab33cfacf468c *man/addPlot.RTF.Rd
2f278c65a29ee0f9780a2fc94572817b *man/addPng.RTF.Rd
566ce79c3a3207761eab7540812ab702 *man/addSessionInfo.RTF.Rd
985d3bdcf247dfd763d596f9ae7bdbc5 *man/addTable.RTF.Rd
1575c4e13e225453f67ba37fe84af76d *man/addText.RTF.Rd
Expand All @@ -27,4 +28,4 @@ a24b38a04d6d5bf5bfb00daf57bccaca *man/endParagraph.RTF.Rd
1019bdd11f883d4e8101dbe5d45882f8 *man/setFontSize.RTF.Rd
6996405d7499ca51fd3bf9c001a730cf *man/startParagraph.RTF.Rd
f6396c7b326935a6b56da44ca56b6545 *man/view.RTF.Rd
d9a21a91edb71aa2d29a15cef516e2bb *tests/tests.R
b9b0d79be11e037bed249b19e22819e3 *tests/tests.R
7 changes: 7 additions & 0 deletions NEWS
@@ -1,3 +1,10 @@
CHANGES IN 0.4-4 (2012-04-11)
-----------------------------
Added documentation to output ggplot2 plots.
Added generic addPng method for inserting existing images.
Fixed output of some UTF-8 symbols method that were not being escaped properly.
Fixed a problem with the row.names parameter in addTable for data.frames.

CHANGES IN 0.4-3 (2011-10-03)
-----------------------------
Added NAMESPACE as required for packages in R-2.14.0.
Expand Down
1 change: 1 addition & 0 deletions R/000.R
Expand Up @@ -9,3 +9,4 @@ autoload("appendVarArgs", package="R.oo")
autoload("hasVarArgs", package="R.oo")
autoload("setMethodS3", package="R.oo")
autoload("setConstructorS3", package="R.oo")
autoload("gsubfn", package="gsubfn")
1 change: 1 addition & 0 deletions R/999.NonDocumentedObjects.R
Expand Up @@ -15,6 +15,7 @@
# @alias increaseIndent
# @alias setFontSize
# @alias addPlot
# @alias addPng
# @alias addTrellisObject
# @alias addSessionInfo
#
Expand Down
88 changes: 74 additions & 14 deletions R/rtf.R
Expand Up @@ -519,7 +519,14 @@ setMethodS3("setFontSize", "RTF", function(this, font.size, ...) {
# }
#
# \details{
# Plots are added to the document as PNG objects.
# Plots are added to the document as PNG objects. This function will work with all
# base graphics methods for plotting. For more sophisticated plots, you may need to
# wrap your plot code into a function, and then pass a reference to that function to
# this method. The parameters for the plot method would then get passed in as '...'
# above.
#
# To output a ggplot2 plot, simply assign the plot to a variable. Then use 'print'
# as the plot function and pass in the plot variable assigned above.
# }
#
# \examples{
Expand All @@ -542,6 +549,39 @@ setMethodS3("addPlot", "RTF", function(this,plot.fun=plot.fun,width=3.0,height=0
}
})

#########################################################################/**
# @RdocMethod addPng
#
# @title "Insert an existing PNG image into the RTF document"
#
# \description{
# @get "title".
# }
#
# @synopsis
#
# \arguments{
# \item{this}{An RTF object.}
# \item{file}{Image file path.}
# \item{width}{Plot output width in inches.}
# \item{height}{Plot output height in inches.}
# \item{...}{Not used.}
# }
#
# \details{
# Add existing PNG file to RTF document.
# }
#
# @author
#
# \seealso{
# @seeclass
# }
#*/#########################################################################
setMethodS3("addPng", "RTF", function(this,file,width=3.0,height=0.3, ...) {
this$.rtf <- paste(this$.rtf,.add.png(file,width=width,height=height,verbose=FALSE),sep="")
})

#########################################################################/**
# @RdocMethod addTrellisObject
#
Expand Down Expand Up @@ -944,23 +984,32 @@ setMethodS3("addSessionInfo", "RTF", function(this, locale = TRUE, ...) {
}

.convert<-function(x) {
x<-gsub("\\n"," \\\\line ",x) # .convert new line to RTF \line
#x<-gsub("\\t"," \\\\tab ",x) # .convert tab to RTF \tab
x<-gsub("<=","\\\\u8804\\\\3",x) # .convert <= to RTF symbol
x<-gsub(">=","\\\\u8805\\\\3",x) # .convert >= to RTF symbol
# http://www.ssec.wisc.edu/~tomw/java/unicode.html
#x<-gsubfn("\\u(\\d+)", .hex2dec, x, engine="R") # format UTF-8 characters from hex to dec
#x<-gsub("\\u(\\d+)","\\\\u\\1\\\\3",x) # format UTF-8 characters from hex to dec

x<-gsub(":delta:","\\\\u0916\\\\3",x) # .convert :delta: to uppercase Greek delta
x<-gsub("\\n"," \\\\line ",x) # convert new line to RTF \line
#x<-gsub("\\t"," \\\\tab ",x) # convert tab to RTF \tab
x<-gsub("<=","\\\\u8804\\\\3",x) # convert <= to RTF symbol
x<-gsub(">=","\\\\u8805\\\\3",x) # convert >= to RTF symbol

x<-gsub("&alpha;","\\\\u0945\\\\3",x) # .convert &alpha; to lowercase Greek alpha
x<-gsub("&beta;","\\\\u0946\\\\3",x) # .convert &beta; to lowercase Greek beta
x<-gsub("&delta;","\\\\u0947\\\\3",x) # .convert &delta; to lowercase Greek delta
x<-gsub("&gamma;","\\\\u0948\\\\3",x) # .convert &gamma; to lowercase Greek gamma
x<-gsub(":delta:","\\\\u0916\\\\3",x) # convert :delta: to uppercase Greek delta

x<-gsub("&Alpha;","\\\\u0913\\\\3",x) # .convert &Alpha; to uppercase Greek alpha
x<-gsub("&Beta;","\\\\u0914\\\\3",x) # .convert &Beta; to uppercase Greek beta
x<-gsub("&Delta;","\\\\u0915\\\\3",x) # .convert &Delta; to uppercase Greek delta
x<-gsub("&Gamma;","\\\\u0916\\\\3",x) # .convert &Gamma; to uppercase Greek gamma
x<-gsub("&alpha;","\\\\u0945\\\\3",x) # convert &alpha; to lowercase Greek alpha
x<-gsub("&beta;","\\\\u0946\\\\3",x) # convert &beta; to lowercase Greek beta
x<-gsub("&gamma;","\\\\u0948\\\\3",x) # convert &gamma; to lowercase Greek gamma
x<-gsub("&delta;","\\\\u0947\\\\3",x) # convert &delta; to lowercase Greek delta
x<-gsub("&epsilon;","\\\\u0949\\\\3",x) # convert &epsilon; to lowercase Greek epsilon
x<-gsub("&theta;","\\\\u0952\\\\3",x) # convert &theta; to lowercase Greek theta
x<-gsub("&kappa;","\\\\u0954\\\\3",x) # convert &kappa; to lowercase Greek kappa

x<-gsub("&Alpha;","\\\\u0913\\\\3",x) # convert &Alpha; to uppercase Greek alpha
x<-gsub("&Beta;","\\\\u0914\\\\3",x) # convert &Beta; to uppercase Greek beta
x<-gsub("&Gamma;","\\\\u0916\\\\3",x) # convert &Gamma; to uppercase Greek gamma
x<-gsub("&Delta;","\\\\u0915\\\\3",x) # convert &Delta; to uppercase Greek delta
x<-gsub("&Epsilon;","\\\\u0917\\\\3",x) # convert &Epsilon; to uppercase Greek epsilon
x<-gsub("&Theta;","\\\\u0920\\\\3",x) # convert &Theta; to uppercase Greek theta
x<-gsub("&Kappa;","\\\\u0922\\\\3",x) # convert &Kappa; to lowercase Greek kappa

x<-gsub("TRUE","Yes",x)
x<-gsub("FALSE","No",x)
Expand Down Expand Up @@ -1148,3 +1197,14 @@ setMethodS3("addSessionInfo", "RTF", function(this, locale = TRUE, ...) {

col.widths
}

.hex2dec <- function(hexadecimal) {
hexdigits <- c(0:9, LETTERS[1:6])
hexadecimal <- toupper(hexadecimal) # treat upper/lower case the same
decimal <- rep(0, length(hexadecimal))
for (i in 1:length(hexadecimal)) {
digits <- match(strsplit(hexadecimal[i],"")[[1]], hexdigits) - 1
decimal[i] <- sum(digits * 16^((length(digits)-1):0))
}
return(decimal)
}
1 change: 1 addition & 0 deletions man/Non-documented_objects.Rd
Expand Up @@ -25,6 +25,7 @@
\alias{increaseIndent}
\alias{setFontSize}
\alias{addPlot}
\alias{addPng}
\alias{addTrellisObject}
\alias{addSessionInfo}

Expand Down
1 change: 1 addition & 0 deletions man/RTF.Rd
Expand Up @@ -51,6 +51,7 @@ extends \link[R.oo]{Object}\cr
\tab \code{\link[rtf:addPageBreak.RTF]{addPageBreak}} \tab Insert a page break into the RTF document optionally specifying new page settings.\cr
\tab \code{\link[rtf:addParagraph.RTF]{addParagraph}} \tab Insert a paragraph into the RTF document.\cr
\tab \code{\link[rtf:addPlot.RTF]{addPlot}} \tab Insert a plot into the RTF document.\cr
\tab \code{\link[rtf:addPng.RTF]{addPng}} \tab Insert an existing PNG image into the RTF document.\cr
\tab \code{\link[rtf:addSessionInfo.RTF]{addSessionInfo}} \tab Insert session information into the RTF document.\cr
\tab \code{\link[rtf:addTable.RTF]{addTable}} \tab Insert a table into the RTF document.\cr
\tab \code{\link[rtf:addText.RTF]{addText}} \tab Insert text into the RTF document.\cr
Expand Down
9 changes: 8 additions & 1 deletion man/addPlot.RTF.Rd
Expand Up @@ -31,7 +31,14 @@
}

\details{
Plots are added to the document as PNG objects.
Plots are added to the document as PNG objects. This function will work with all
base graphics methods for plotting. For more sophisticated plots, you may need to
wrap your plot code into a function, and then pass a reference to that function to
this method. The parameters for the plot method would then get passed in as '...'
above.

To output a ggplot2 plot, simply assign the plot to a variable. Then use 'print'
as the plot function and pass in the plot variable assigned above.
}

\examples{
Expand Down
42 changes: 42 additions & 0 deletions man/addPng.RTF.Rd
@@ -0,0 +1,42 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do not modify this file since it was automatically generated from:
%
% rtf.R
%
% by the Rdoc compiler part of the R.oo package.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\name{addPng.RTF}
\alias{addPng.RTF}
\alias{RTF.addPng}
\alias{addPng.RTF}
\alias{addPng,RTF-method}


\title{Insert an existing PNG image into the RTF document}

\description{
Insert an existing PNG image into the RTF document.
}

\usage{\method{addPng}{RTF}(this, file, width=3, height=0.3, ...)}

\arguments{
\item{this}{An RTF object.}
\item{file}{Image file path.}
\item{width}{Plot output width in inches.}
\item{height}{Plot output height in inches.}
\item{...}{Not used.}
}

\details{
Add existing PNG file to RTF document.
}

\author{Michael E. Schaffer}

\seealso{
For more information see \code{\link{RTF}}.
}
\keyword{internal}
\keyword{methods}
4 changes: 3 additions & 1 deletion tests/tests.R
Expand Up @@ -84,7 +84,9 @@ colnames(tab)<-paste("C",c(1:ncols),sep="")
addParagraph(rtf,"\n\nAnother table based on a 'data.frame' class with automatic column widths (multi-word/mixed case)\n")
addTable(rtf,tab,font.size=10,row.names=TRUE,NA.string="-")


# Try some UTF-8 output
addParagraph(rtf,"\n\nTry some UTF-8 output in a table\n")
addTable(rtf,data.frame(utf="\u2586"),font.size=10,row.names=FALSE,NA.string="-")

addNewLine(rtf)
addNewLine(rtf)
Expand Down

0 comments on commit d4d5a77

Please sign in to comment.