Title: | Reproducible Research with a Table of R Codes |
---|---|
Description: | Makes documents containing plots and tables from a table of R codes. Can make "HTML", "pdf('LaTex')", "docx('MS Word')" and "pptx('MS Powerpoint')" documents with or without R code. In the package, modularized 'shiny' app codes are provided. These modules are intended for reuse across applications. |
Authors: | Keon-Woong Moon [aut, cre] |
Maintainer: | Keon-Woong Moon <[email protected]> |
License: | GPL-3 |
Version: | 0.3.2 |
Built: | 2025-02-08 05:24:21 UTC |
Source: | https://github.com/cardiomoon/rrtable |
Add two flextables into a document object
add_2flextables(mydoc, ft1, ft2, echo = FALSE, width = 3, code = "")
add_2flextables(mydoc, ft1, ft2, echo = FALSE, width = 3, code = "")
mydoc |
A document object |
ft1 |
The first flextable |
ft2 |
The second flextable |
echo |
whether or not display R code |
width |
plot width in inches |
code |
R code string |
a document object
## Not run: require(rrtable) require(officer) require(magrittr) title="Two Tables" ft1=df2flextable(head(iris[1:4])) ft2=df2flextable(tail(iris[1:4])) doc=read_docx() doc %>% add_text(title=title) %>% add_2flextables(ft1,ft2) doc=read_pptx() doc %>% add_text(title=title) %>% add_2flextables(ft1,ft2) ## End(Not run)
## Not run: require(rrtable) require(officer) require(magrittr) title="Two Tables" ft1=df2flextable(head(iris[1:4])) ft2=df2flextable(tail(iris[1:4])) doc=read_docx() doc %>% add_text(title=title) %>% add_2flextables(ft1,ft2) doc=read_pptx() doc %>% add_text(title=title) %>% add_2flextables(ft1,ft2) ## End(Not run)
Add two ggplots into a document object
add_2ggplots(mydoc, plot1, plot2, width = 3, height = 2.5, top = 2)
add_2ggplots(mydoc, plot1, plot2, width = 3, height = 2.5, top = 2)
mydoc |
A document object |
plot1 |
An R code encoding the first ggplot |
plot2 |
An R code encoding the second ggplot |
width |
plot width in inches |
height |
plot height in inches |
top |
top plot position in inches |
a document object
## Not run: require(ggplot2) require(magrittr) require(officer) require(rvg) plot1 <- "ggplot(data = iris, aes(Sepal.Length, Petal.Length)) + geom_point()" plot2 <- "ggplot(data = iris, aes(Sepal.Length, Petal.Length, color = Species)) + geom_point()" read_pptx() %>% add_text(title="Two ggplots") %>% add_2ggplots(plot1=plot1,plot2=plot2) read_docx() %>% add_text(title="Two ggplots") %>% add_2ggplots(plot1=plot1,plot2=plot2) ## End(Not run)
## Not run: require(ggplot2) require(magrittr) require(officer) require(rvg) plot1 <- "ggplot(data = iris, aes(Sepal.Length, Petal.Length)) + geom_point()" plot2 <- "ggplot(data = iris, aes(Sepal.Length, Petal.Length, color = Species)) + geom_point()" read_pptx() %>% add_text(title="Two ggplots") %>% add_2ggplots(plot1=plot1,plot2=plot2) read_docx() %>% add_text(title="Two ggplots") %>% add_2ggplots(plot1=plot1,plot2=plot2) ## End(Not run)
Add two plots into a document object
add_2plots( mydoc, plotstring1, plotstring2, plottype = "auto", width = NULL, height = NULL, echo = FALSE, top = 2 )
add_2plots( mydoc, plotstring1, plotstring2, plottype = "auto", width = NULL, height = NULL, echo = FALSE, top = 2 )
mydoc |
A document object |
plotstring1 |
An R code string encoding the first plot |
plotstring2 |
An R code string encoding the second plot |
plottype |
character One of c("auto","plot","ggplot") |
width |
plot width in inches |
height |
plot height in inches |
echo |
logical Whether or not show R code |
top |
top plot position in inches |
a document object
require(magrittr) require(officer) require(ggplot2) plotstring1="plot(iris)" plotstring2="ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point()" read_pptx() %>% add_text(title="Two plots") %>% add_2plots(plotstring1,plotstring2) read_docx() %>% add_text(title="Two plots") %>% add_2plots(plotstring1,plotstring2)
require(magrittr) require(officer) require(ggplot2) plotstring1="plot(iris)" plotstring2="ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point()" read_pptx() %>% add_text(title="Two plots") %>% add_2plots(plotstring1,plotstring2) read_docx() %>% add_text(title="Two plots") %>% add_2plots(plotstring1,plotstring2)
Add a ggplot or a plot to the Microsoft Office Document
add_anyplot( doc, x = NULL, plottype = "auto", left = 1, top = 2, width = 8, height = 5.5 )
add_anyplot( doc, x = NULL, plottype = "auto", left = 1, top = 2, width = 8, height = 5.5 )
doc |
A document object |
x |
An object of class ggplot2 or a string encoding plot or ggplot |
plottype |
character One of c("auto","plot","ggplot","emf") |
left |
left margin |
top |
top margin |
width |
desired width of the plot |
height |
desired height of the plot |
Add a flextable or mytable object into a document object
add_flextable(mydoc, ftable, echo = FALSE, code = "", landscape = FALSE)
add_flextable(mydoc, ftable, echo = FALSE, code = "", landscape = FALSE)
mydoc |
A document object |
ftable |
A flextable or mytable object |
echo |
whether or not display R code |
code |
R code string |
landscape |
Logical. Whether or not make a landscape section. |
a document object
## Not run: require(rrtable) require(moonBook) require(officer) require(magrittr) ftable=mytable(Dx~.,data=acs) title="mytable Example" ft=df2flextable(head(iris)) title2="df2flextable Example" doc=read_docx() doc %>% add_text(title=title) %>% add_flextable(ftable) %>% add_text(title=title2) %>% add_flextable(ft) ## End(Not run)
## Not run: require(rrtable) require(moonBook) require(officer) require(magrittr) ftable=mytable(Dx~.,data=acs) title="mytable Example" ft=df2flextable(head(iris)) title2="df2flextable Example" doc=read_docx() doc %>% add_text(title=title) %>% add_flextable(ftable) %>% add_text(title=title2) %>% add_flextable(ft) ## End(Not run)
Add ggplot into a document object
add_ggplot(mydoc, code = "", top = 2)
add_ggplot(mydoc, code = "", top = 2)
mydoc |
A document object |
code |
R code for table |
top |
top position of plot |
a document object
require(rrtable) require(ggplot2) require(officer) require(magrittr) code <- "ggplot(mtcars, aes(x = mpg , y = wt)) + geom_point()" read_pptx() %>% add_text(title="ggplot") %>% add_ggplot(code=code) read_docx() %>% add_text(title="ggplot") %>% add_ggplot(code=code)
require(rrtable) require(ggplot2) require(officer) require(magrittr) code <- "ggplot(mtcars, aes(x = mpg , y = wt)) + geom_point()" read_pptx() %>% add_text(title="ggplot") %>% add_ggplot(code=code) read_docx() %>% add_text(title="ggplot") %>% add_ggplot(code=code)
Add plot into a document object
add_image( mydoc, x = NULL, preprocessing = "", left = 1, top = 2, width = 8, height = 5.5, units = "in", res = 300, format = "emf", ... )
add_image( mydoc, x = NULL, preprocessing = "", left = 1, top = 2, width = 8, height = 5.5, units = "in", res = 300, format = "emf", ... )
mydoc |
A document object |
x |
An string of R code encoding plot |
preprocessing |
A string of R code or "" |
left |
left margin |
top |
top margin |
width |
the width of the device. |
height |
the height of the device. |
units |
The units in which height and width are given. Can be px (pixels, the default), in (inches), cm or mm. |
res |
The nominal resolution in ppi which will be recorded in the bitmap file, if a positive integer. Also used for units other than the default, and to convert points to pixels. |
format |
plot format |
... |
additional arguments passed to png() |
a document object
require(officer) require(rrtable) require(magrittr) require(ggplot2) read_pptx() %>% add_text(title="Add image") %>% add_image("plot(iris)") read_docx() %>% add_text(title="Add image") %>% add_image("plot(1:10)",format="png")
require(officer) require(rrtable) require(magrittr) require(ggplot2) read_pptx() %>% add_text(title="Add image") %>% add_image("plot(iris)") read_docx() %>% add_text(title="Add image") %>% add_image("plot(1:10)",format="png")
Add plot into a document object
add_plot(mydoc, plotstring, width = 6, height = 6, top = 2)
add_plot(mydoc, plotstring, width = 6, height = 6, top = 2)
mydoc |
A document object |
plotstring |
String of an R code encoding a plot |
width |
width of plot |
height |
height of plot |
top |
top position of plot |
a document object
require(rrtable) require(officer) require(rvg) require(magrittr) read_pptx() %>% add_text(title="Plot") %>% add_plot("plot(iris)") read_docx() %>% add_text(title="Plot") %>% add_plot("plot(iris)")
require(rrtable) require(officer) require(rvg) require(magrittr) read_pptx() %>% add_text(title="Plot") %>% add_plot("plot(iris)") read_docx() %>% add_text(title="Plot") %>% add_plot("plot(iris)")
Make a R code slide into a document object
add_Rcode(mydoc, code, format = "pptx")
add_Rcode(mydoc, code, format = "pptx")
mydoc |
A document object |
code |
A character string encoding R codes |
format |
desired format. choices are "pptx" or "docx" |
a document object
library(rrtable) library(magrittr) library(officer) code="summary(lm(mpg~hp+wt,data=mtcars))" read_pptx() %>% add_text(title="Regression Analysis") %>% add_Rcode(code)
library(rrtable) library(magrittr) library(officer) code="summary(lm(mpg~hp+wt,data=mtcars))" read_pptx() %>% add_text(title="Regression Analysis") %>% add_Rcode(code)
add self data to document
add_self(mydoc, data)
add_self(mydoc, data)
mydoc |
A document object |
data |
a data.frame |
Add text to document
add_text( mydoc, title = "", text = "", code = "", echo = FALSE, eval = FALSE, style = "Normal", landscape = FALSE )
add_text( mydoc, title = "", text = "", code = "", echo = FALSE, eval = FALSE, style = "Normal", landscape = FALSE )
mydoc |
A document object |
title |
An character string as a plot title |
text |
text string to be added |
code |
An R code string |
echo |
logical Whether or not show R code |
eval |
logical whether or not evaluate the R code |
style |
text style |
landscape |
Logical. Whether or not make a landscape section. |
Add hyperlink text
add_text2hyperlink(mydoc, text)
add_text2hyperlink(mydoc, text)
mydoc |
A document object |
text |
text string to be added |
Add title to docx file
add_title(x, title = "", size = 20, color = NULL, before = TRUE, after = TRUE)
add_title(x, title = "", size = 20, color = NULL, before = TRUE, after = TRUE)
x |
A document object |
title |
Title |
size |
font size |
color |
font color |
before |
Whether or not add blank paragraph before title |
after |
Whether or not add blank paragraph after title |
Add title slide
add_title_slide(mydoc, title = "", subtitle = "")
add_title_slide(mydoc, title = "", subtitle = "")
mydoc |
A document object |
title |
An character string as a title |
subtitle |
An character string as a subtitle |
require(magrittr) require(officer) read_pptx() %>% add_title_slide(title="Web-based analysis with R")
require(magrittr) require(officer) read_pptx() %>% add_title_slide(title="Web-based analysis with R")
coerce an object of type "numeric"
as.mynumeric(x)
as.mynumeric(x)
x |
A vector |
x=c("1,200","2","3.5") x=factor(3:1) x=c(1:3,"tt") as.mynumeric(x)
x=c("1,200","2","3.5") x=factor(3:1) x=c(1:3,"tt") as.mynumeric(x)
Server function of chooser Module
chooser( input, output, session, leftChoices, rightChoices = reactive(c()), size = reactive(0), width = reactive(130) )
chooser( input, output, session, leftChoices, rightChoices = reactive(c()), size = reactive(0), width = reactive(130) )
input |
input |
output |
output |
session |
session |
leftChoices |
choices for left column |
rightChoices |
choices for right column |
size |
number of column lines to be displayed |
width |
width of left and right columns in pixel |
Server function of chooser2 Module
chooser2( input, output, session, leftChoices, rightChoices = reactive(c()), size = reactive(0), width = reactive(130) )
chooser2( input, output, session, leftChoices, rightChoices = reactive(c()), size = reactive(0), width = reactive(130) )
input |
input |
output |
output |
session |
session |
leftChoices |
choices for left column |
rightChoices |
choices for right column |
size |
number of column lines to be displayed |
width |
width of left and right columns in pixel |
UI of chooser2 Module Add 'all select' and 'reset' button to chooser module
chooser2UI(id)
chooser2UI(id)
id |
id |
Chooser Input
chooserInput( inputId, leftLabel, rightLabel, leftChoices, rightChoices, size = 5, multiple = FALSE, width = 100 )
chooserInput( inputId, leftLabel, rightLabel, leftChoices, rightChoices, size = 5, multiple = FALSE, width = 100 )
inputId |
input Id |
leftLabel |
Label for left column |
rightLabel |
Label for right column |
leftChoices |
choices for left column |
rightChoices |
choices for right column |
size |
number of column lines to be displayed |
multiple |
logical enable multiple selection |
width |
width of left and right columns in pixel |
UI of chooser Module
chooserUI(id)
chooserUI(id)
id |
id |
Save plot/ggplot code to Microsoft Powerpoint format
code2docx(...)
code2docx(...)
... |
further arguments to be passed to code2office |
## Not run: code2docx(plot(iris)) require(ggplot2) gg=ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point() code2docx(ggobj=gg) ## End(Not run)
## Not run: code2docx(plot(iris)) require(ggplot2) gg=ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point() code2docx(ggobj=gg) ## End(Not run)
Save plot/ggplot code to Microsoft Powerpoint format
code2office( ..., ggobj = NULL, target = "Report", append = FALSE, title = "", type = "pptx", preprocessing = "", plottype = "auto", echo = FALSE, parallel = FALSE, left = 1, top = 1, width = NULL, height = NULL, aspectr = NULL )
code2office( ..., ggobj = NULL, target = "Report", append = FALSE, title = "", type = "pptx", preprocessing = "", plottype = "auto", echo = FALSE, parallel = FALSE, left = 1, top = 1, width = NULL, height = NULL, aspectr = NULL )
... |
Further argument to be passed to function dml() |
ggobj |
a ggplot object |
target |
name of output file |
append |
logical value |
title |
Optional character vector of plot title |
type |
"pptx" or "docx" |
preprocessing |
A string of R code or "" |
plottype |
character One of c("auto","plot","ggplot","emf") |
echo |
logical. If true, show code. |
parallel |
logical. If true, add two plots side by side |
left |
left margin |
top |
top margin |
width |
desired width of the plot |
height |
desired height of the plot |
aspectr |
desired aspect ratio of the plot |
## Not run: code2office(plot(iris)) require(ggplot2) gg=ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point() code2office(ggobj=gg) ## End(Not run)
## Not run: code2office(plot(iris)) require(ggplot2) gg=ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point() code2office(ggobj=gg) ## End(Not run)
Save plot/ggplot code to Microsoft Powerpoint format
code2pptx(...)
code2pptx(...)
... |
further arguments to be passed to code2office |
## Not run: code2pptx(plot(iris)) require(ggplot2) gg=ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point() code2pptx(ggobj=gg) ## End(Not run)
## Not run: code2pptx(plot(iris)) require(ggplot2) gg=ggplot(data=mtcars,aes(x=wt,y=mpg))+geom_point() code2pptx(ggobj=gg) ## End(Not run)
convert data to docx file
data2docx(...)
data2docx(...)
... |
arguments to be passed to data2office() |
## Not run: library(rrtable) library(moonBook) library(ggplot2) data2docx(sampleData2,echo=TRUE) ## End(Not run)
## Not run: library(rrtable) library(moonBook) library(ggplot2) data2docx(sampleData2,echo=TRUE) ## End(Not run)
Make a word file with a data.frame
data2docx2(...)
data2docx2(...)
... |
further arguments to be passed to data2HTML |
Make a HTML5 file with a data.frame
data2HTML( data, preprocessing = "", path = ".", filename = "report.HTML", rawDataName = NULL, rawDataFile = "rawData.RDS", type = "HTML", vanilla = FALSE, echo = TRUE, showself = FALSE, out = NULL )
data2HTML( data, preprocessing = "", path = ".", filename = "report.HTML", rawDataName = NULL, rawDataFile = "rawData.RDS", type = "HTML", vanilla = FALSE, echo = TRUE, showself = FALSE, out = NULL )
data |
A data.frame |
preprocessing |
A character string of R code |
path |
A name of destination file path |
filename |
A name of destination file |
rawDataName |
The name of the rawData |
rawDataFile |
The name of the rawData file which the data are to be read from. |
type |
character "HTML" or "pdf" |
vanilla |
logical. Whether or not make vanilla table |
echo |
Logical. Whether or not show R code of plot and table |
showself |
Logical. Whether or not show R code for the paragraph |
out |
An object or NULL |
## Not run: library(moonBook) library(rrtable) library(ggplot2) data2HTML(sampleData2) ## End(Not run)
## Not run: library(moonBook) library(rrtable) library(ggplot2) data2HTML(sampleData2) ## End(Not run)
convert data to pptx file
data2office( data, preprocessing = "", path = ".", filename = "Report", format = "pptx", width = 7, height = 5, units = "in", res = 300, rawDataName = NULL, rawDataFile = "rawData.RDS", vanilla = FALSE, echo = FALSE, landscape = FALSE, showself = FALSE, out = NULL )
data2office( data, preprocessing = "", path = ".", filename = "Report", format = "pptx", width = 7, height = 5, units = "in", res = 300, rawDataName = NULL, rawDataFile = "rawData.RDS", vanilla = FALSE, echo = FALSE, landscape = FALSE, showself = FALSE, out = NULL )
data |
A document object |
preprocessing |
A string |
path |
A name of destination file path |
filename |
File name |
format |
desired format. choices are "pptx" or "docx" |
width |
the width of the device. |
height |
the height of the device. |
units |
The units in which height and width are given. Can be px (pixels, the default), in (inches), cm or mm. |
res |
The nominal resolution in ppi which will be recorded in the bitmap file, if a positive integer. Also used for units other than the default, and to convert points to pixels. |
rawDataName |
raw Data Name |
rawDataFile |
raw Data File |
vanilla |
logical. Whether or not make vanilla table |
echo |
logical Whether or not show R code |
landscape |
Logical. Whether or not make a landscape section. |
showself |
Logical. Whether or not show R code for the paragraph |
out |
An object or NULL |
Make a pdf file with a data.frame
data2pdf(...)
data2pdf(...)
... |
further arguments to be passed to data2HTML |
library(moonBook) library(ztable) library(ggplot2) ## Not run: data2pdf(sampleData2) ## End(Not run)
library(moonBook) library(ztable) library(ggplot2) ## Not run: data2pdf(sampleData2) ## End(Not run)
Make zipped plot file with a data.frame
data2plotzip( data, path = ".", filename = "Plot.zip", format = "PNG", width = 8, height = 6, units = "in", res = 300, start = 0, preprocessing = "", rawDataName = NULL, rawDataFile = "rawData.RDS", out = NULL )
data2plotzip( data, path = ".", filename = "Plot.zip", format = "PNG", width = 8, height = 6, units = "in", res = 300, start = 0, preprocessing = "", rawDataName = NULL, rawDataFile = "rawData.RDS", out = NULL )
data |
A data.frame |
path |
A name of destination file path |
filename |
A path of destination file |
format |
Plot format. Choices are c("PNG","SVG","PDF") |
width |
A plot width |
height |
A plot height |
units |
The units in which height and width are given. Can be px (pixels, the default), in (inches), cm or mm. |
res |
The nominal resolution in ppi |
start |
Plot start number |
preprocessing |
A character string of R code |
rawDataName |
The name of the rawData |
rawDataFile |
The name of the rawData file which the data are to be read from. |
out |
An object or NULL |
## Not run: library(moonBook) library(ztable) library(rrtable) library(ggplot2) data2plotzip(sampleData2,path="tmp") ## End(Not run)
## Not run: library(moonBook) library(ztable) library(rrtable) library(ggplot2) data2plotzip(sampleData2,path="tmp") ## End(Not run)
convert data to pptx file
data2pptx(...)
data2pptx(...)
... |
arguments to be passed to data2office() |
## Not run: library(rrtable) library(moonBook) library(ggplot2) data2pptx(sampleData2,echo=TRUE) ## End(Not run)
## Not run: library(rrtable) library(moonBook) library(ggplot2) data2pptx(sampleData2,echo=TRUE) ## End(Not run)
Make a Powerpoint file with a data.frame
data2pptx2(...)
data2pptx2(...)
... |
further arguments to be passed to data2HTML |
Convert data.frame to flextable
df2flextable( df, vanilla = FALSE, fontname = NULL, fontsize = 12, add.rownames = FALSE, even_header = "transparent", odd_header = "#5B7778", even_body = "#EFEFEF", odd_body = "transparent", vlines = TRUE, colorheader = FALSE, digits = 2, digitp = 3, align_header = "center", align_body = "right", align_rownames = "left", NA2space = TRUE, pcol = NULL, ... )
df2flextable( df, vanilla = FALSE, fontname = NULL, fontsize = 12, add.rownames = FALSE, even_header = "transparent", odd_header = "#5B7778", even_body = "#EFEFEF", odd_body = "transparent", vlines = TRUE, colorheader = FALSE, digits = 2, digitp = 3, align_header = "center", align_body = "right", align_rownames = "left", NA2space = TRUE, pcol = NULL, ... )
df |
A data.frame |
vanilla |
A Logical |
fontname |
Font name |
fontsize |
font size |
add.rownames |
logical. Whether or not include rownames |
even_header |
background color of even_header |
odd_header |
background color of even_header |
even_body |
background color of even_body |
odd_body |
background color of even_body |
vlines |
Logical. Whether or not draw vertical lines |
colorheader |
Logical. Whether or not use color in header |
digits |
integer indicating the number of decimal places |
digitp |
integer indicating the number of decimal places of p values |
align_header |
alignment of header. Expected value is one of 'left', 'right', 'center', 'justify'. |
align_body |
alignment of body. Expected value is one of 'left', 'right', 'center', 'justify'. |
align_rownames |
alignment of rownames. Expected value is one of 'left', 'right', 'center', 'justify'. |
NA2space |
A logical. If true, convert NA value to space |
pcol |
An integer indicating p value. If specified, convert value less than 0.01 to "< 0.001" in given column. |
... |
further arguments to be passed to flextable |
require(flextable) require(officer) df2flextable(head(iris),vanilla=TRUE,colorheader=TRUE) ## Not run: df2flextable(head(iris),vanilla=TRUE,digits=c(1,2,3,4)) df2flextable(head(iris),vanilla=FALSE) df2flextable(head(iris),vanilla=FALSE,vlines=FALSE,fontsize=14) df2flextable(head(mtcars/2000),digits=3,pcol=8,digitp=4,add.rownames=TRUE) ## End(Not run)
require(flextable) require(officer) df2flextable(head(iris),vanilla=TRUE,colorheader=TRUE) ## Not run: df2flextable(head(iris),vanilla=TRUE,digits=c(1,2,3,4)) df2flextable(head(iris),vanilla=FALSE) df2flextable(head(iris),vanilla=FALSE,vlines=FALSE,fontsize=14) df2flextable(head(mtcars/2000),digits=3,pcol=8,digitp=4,add.rownames=TRUE) ## End(Not run)
Make flextable with limited width
df2flextable2(df, mincol = 0.7, maxcol = 4, ...)
df2flextable2(df, mincol = 0.7, maxcol = 4, ...)
df |
a data.frame |
mincol |
minimum column width in inch |
maxcol |
maximum column width in inch |
... |
further arguments to be passed to df2flextable() |
Make a flextable with a data.frame
df2RcodeTable(df, bordercolor = "gray", format = "pptx", eval = TRUE)
df2RcodeTable(df, bordercolor = "gray", format = "pptx", eval = TRUE)
df |
A data.frame |
bordercolor |
A border color name |
format |
desired format. choices are "pptx" or "docx" |
eval |
logical. Whether or not evaluate the code |
A flextable object
Export pptxList file to desired format
exportCSV( file, format = "HTML", rawDataName = NULL, rawDataFile = "rawData.RDS" )
exportCSV( file, format = "HTML", rawDataName = NULL, rawDataFile = "rawData.RDS" )
file |
The name of the file which the data are to be read from. |
format |
desired output format. Possible choices are one of the c("HTML","pdf","word","pptx","plotzip") |
rawDataName |
The name of the rawData |
rawDataFile |
The name of the rawData file which the data are to be read from. |
read data file and make a docx file
file2docx(file, selected = NULL, ...)
file2docx(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2docx() |
read data file and make a docx file with Rmd file
file2docx2(file, selected = NULL, ...)
file2docx2(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2docx() |
read data file and make a HTML file
file2HTML(file, selected = NULL, ...)
file2HTML(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2HTML() |
read data file and make a pdf file
file2pdf(file, selected = NULL, ...)
file2pdf(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2pdf() |
read data file and make a zip file with plots
file2plotzip(file, selected = NULL, ...)
file2plotzip(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2plotzip() |
read data file and make a pptx file
file2pptx(file, selected = NULL, ...)
file2pptx(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2pptx() |
read data file and make a pptx file with Rmd file
file2pptx2(file, selected = NULL, ...)
file2pptx2(file, selected = NULL, ...)
file |
The name of the file which the data are to be read from. |
selected |
A numeric vector or NULL(default). If specified, only selected data are printed. |
... |
Further argument to be passed to data2pptx() |
Convert flextable to ztable
flextable2ztable(ft, type = "html", ...)
flextable2ztable(ft, type = "html", ...)
ft |
An object of class flextable |
type |
"html" or "latex" |
... |
Further argument to be passed to ztable |
an object of class ztable
Convert html5 code to latex
html2latex(df)
html2latex(df)
df |
A data.frame |
Convert HTML table to latex table
HTMLcode2latex(data)
HTMLcode2latex(data)
data |
a data.frame |
Save plot/ggplot to Microsoft Word format
image2docx(...)
image2docx(...)
... |
further arguments to be passed to image2office |
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() image2docx(x) image2docx(x="plot(iris)",title="A ggplot",append=TRUE) p2="ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point()" image2docx(p2,append=TRUE) ## End(Not run)
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() image2docx(x) image2docx(x="plot(iris)",title="A ggplot",append=TRUE) p2="ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point()" image2docx(p2,append=TRUE) ## End(Not run)
Save plot/ggplot as image to Microsoft Powerpoint format
image2office( x, target = "Report", append = FALSE, title = "", type = "pptx", preprocessing = "", left = 1, top = 1, width = 8, height = 5.5 )
image2office( x, target = "Report", append = FALSE, title = "", type = "pptx", preprocessing = "", left = 1, top = 1, width = 8, height = 5.5 )
x |
A string vector encoding plot or ggplot |
target |
name of output file |
append |
logical value |
title |
Optional character vector of plot title |
type |
"pptx" or "docx" |
preprocessing |
A string of R code or "" |
left |
left margin |
top |
top margin |
width |
desired width of the plot |
height |
desired height of the plot |
## Not run: require(ggplot2) image2pptx("ggplot(data=iris,aes(x=Sepal.Length))+geom_density()") ## End(Not run)
## Not run: require(ggplot2) image2pptx("ggplot(data=iris,aes(x=Sepal.Length))+geom_density()") ## End(Not run)
Save plot/ggplot to Microsoft Powerpoint format
image2pptx(...)
image2pptx(...)
... |
further arguments to be passed to image2office |
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() image2pptx(x) x="plot(iris)" image2pptx(x,title="A plot",append=TRUE) p2="ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point()" image2pptx(p2,append=TRUE) ## End(Not run)
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() image2pptx(x) x="plot(iris)" image2pptx(x,title="A plot",append=TRUE) p2="ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point()" image2pptx(p2,append=TRUE) ## End(Not run)
replace argument of a function
insert_argument(code, argument, value)
insert_argument(code, argument, value)
code |
string of function call |
argument |
argument of function to be set |
value |
value to be set |
Reports whether plotstring encode a ggplot object
is_ggplot(plotstring)
is_ggplot(plotstring)
plotstring |
A character |
require(ggplot2) is_ggplot("plot(iris)") is_ggplot("ggplot(iris,aes(x=Sepal.Length))+geom_histogram()")
require(ggplot2) is_ggplot("plot(iris)") is_ggplot("ggplot(iris,aes(x=Sepal.Length))+geom_histogram()")
Reports whether plotstring encode a ggsurvplot object
is_ggsurvplot(x)
is_ggsurvplot(x)
x |
A character encoding a plot |
Concatenate to file
mycat(..., file = "report2.Rmd")
mycat(..., file = "report2.Rmd")
... |
R object |
file |
A connection |
Make flextable with a data.frame
myFlextable(df, numericCol = NULL)
myFlextable(df, numericCol = NULL)
df |
A data.frame |
numericCol |
Numeric. Columns to be treated as numeric |
grep string in all files in subdirectory
mygrep(x, file = "*")
mygrep(x, file = "*")
x |
string |
file |
files to seek |
Make zipped plots with a data.frame
myplot2( data, format = "PNG", width = 7, height = 7, units = "in", res = 300, start = 0, rawDataName = NULL, rawDataFile = "rawData.RDS" )
myplot2( data, format = "PNG", width = 7, height = 7, units = "in", res = 300, start = 0, rawDataName = NULL, rawDataFile = "rawData.RDS" )
data |
A data.frame |
format |
Plot format. Choices are c("PNG","SVG","PDF") |
width |
A plot width |
height |
A plot height |
units |
The units in which height and width are given. Can be px (pixels, the default), in (inches), cm or mm. |
res |
The nominal resolution in ppi |
start |
Plot start number |
rawDataName |
The name of the rawData |
rawDataFile |
The name of the rawData file which the data are to be read from. |
Convert mytable object to flextable
mytable2flextable(result, vanilla = TRUE, fontname = NULL, fontsize = 10)
mytable2flextable(result, vanilla = TRUE, fontname = NULL, fontsize = 10)
result |
An object of class "mytable" |
vanilla |
A Logical. |
fontname |
Font name |
fontsize |
font size |
## Not run: require(moonBook) require(flextable) require(officer) result=mytable(smoking+Dx~.,data=acs) mytable2flextable(result) mytable2flextable(result,vanilla=FALSE) result=mytable(Dx~.,data=acs) mytable2flextable(result) mytable2flextable(result,vanilla=FALSE) ## End(Not run)
## Not run: require(moonBook) require(flextable) require(officer) result=mytable(smoking+Dx~.,data=acs) mytable2flextable(result) mytable2flextable(result,vanilla=FALSE) result=mytable(Dx~.,data=acs) mytable2flextable(result) mytable2flextable(result,vanilla=FALSE) ## End(Not run)
Make/open office document with file name
open_doc(target = "Report", type = "pptx", append = FALSE)
open_doc(target = "Report", type = "pptx", append = FALSE)
target |
name of output file |
type |
"pptx" or "docx" |
append |
logical |
Change p value to string
p2character(x, digits = 3)
p2character(x, digits = 3)
x |
A numeric vector |
digits |
integer indicating the number of decimal places |
x=c(0.000001,NA,0.1234567,0.00123,0.000123) p2character(x) p2character(x,digits=4)
x=c(0.000001,NA,0.1234567,0.00123,0.000123) p2character(x) p2character(x,digits=4)
Side by side pickerInput
pickerInput3(...)
pickerInput3(...)
... |
Further arguments to be passed to pickerInput |
Save plot/ggplot to Microsoft Word format
plot2docx(...)
plot2docx(...)
... |
further arguments to be passed to plot2office |
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() plot2docx(x) plot2docx(x,title="A ggplot",append=TRUE) p2=ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point() plot2docx(p2,append=TRUE) plot2docx(x="plot(iris)",append=TRUE,title="plot(iris)") plot2docx(x="ggplot(iris,aes(x=Sepal.Length))+geom_histogram()",append=TRUE) ## End(Not run)
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() plot2docx(x) plot2docx(x,title="A ggplot",append=TRUE) p2=ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point() plot2docx(p2,append=TRUE) plot2docx(x="plot(iris)",append=TRUE,title="plot(iris)") plot2docx(x="ggplot(iris,aes(x=Sepal.Length))+geom_histogram()",append=TRUE) ## End(Not run)
Save plot/ggplot to Microsoft Powerpoint format
plot2office( x = NULL, target = "Report", append = FALSE, title = "", type = "pptx", preprocessing = "", plottype = "auto", echo = FALSE, parallel = FALSE, left = 1, top = 1, width = NULL, height = NULL, aspectr = NULL, out = NULL )
plot2office( x = NULL, target = "Report", append = FALSE, title = "", type = "pptx", preprocessing = "", plottype = "auto", echo = FALSE, parallel = FALSE, left = 1, top = 1, width = NULL, height = NULL, aspectr = NULL, out = NULL )
x |
An object of class ggplot2 or a string vector encoding plot or ggplot |
target |
name of output file |
append |
logical value |
title |
Optional character vector of plot title |
type |
"pptx" or "docx" |
preprocessing |
A string of R code or "" |
plottype |
character One of c("auto","plot","ggplot","emf") |
echo |
logical. If true, show code. |
parallel |
logical. If true, add two plots side by side |
left |
left margin |
top |
top margin |
width |
desired width of the plot |
height |
desired height of the plot |
aspectr |
desired aspect ratio of the plot |
out |
An object or NULL |
## Not run: require(ggplot2) x=c("plot(iris)","ggplot(mtcars,aes(x=hp,y=mpg))+geom_point()") plot2office(x,title="2 plots",parallel=TRUE) plot2office(x,title="2 plots",parallel=TRUE,echo=TRUE,append=TRUE) plot2office(x,parallel=TRUE,echo=TRUE,append=TRUE) ## End(Not run)
## Not run: require(ggplot2) x=c("plot(iris)","ggplot(mtcars,aes(x=hp,y=mpg))+geom_point()") plot2office(x,title="2 plots",parallel=TRUE) plot2office(x,title="2 plots",parallel=TRUE,echo=TRUE,append=TRUE) plot2office(x,parallel=TRUE,echo=TRUE,append=TRUE) ## End(Not run)
Save plot/ggplot to Microsoft Powerpoint format
plot2pptx(...)
plot2pptx(...)
... |
further arguments to be passed to plot2office |
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() plot2pptx(x) plot2pptx(x,title="A ggplot",append=TRUE) p2=ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point() plot2pptx(p2,append=TRUE) plot2pptx(x=c("plot(iris)","ggplot(iris,aes(x=Sepal.Length))+geom_histogram()"), append=TRUE,title=c("plot","ggplot"),echo=TRUE) ## End(Not run)
## Not run: require(ggplot2) x<-ggplot(iris,aes(x=Sepal.Length))+geom_histogram() plot2pptx(x) plot2pptx(x,title="A ggplot",append=TRUE) p2=ggplot(iris,aes(x=Sepal.Length,y=Sepal.Width))+geom_point() plot2pptx(p2,append=TRUE) plot2pptx(x=c("plot(iris)","ggplot(iris,aes(x=Sepal.Length))+geom_histogram()"), append=TRUE,title=c("plot","ggplot"),echo=TRUE) ## End(Not run)
Make png file with a plot code
plotPNG2( x, file, type, width = 7, height = 7, units = "in", res = 300, ggplot = FALSE )
plotPNG2( x, file, type, width = 7, height = 7, units = "in", res = 300, ggplot = FALSE )
x |
A R code string for plot |
file |
A path of destination file |
type |
A character |
width |
A plot width |
height |
A plot height |
units |
The units in which height and width are given. Can be px (pixels, the default), in (inches), cm or mm. |
res |
The nominal resolution in ppi |
ggplot |
A logical. Set this argument true if the R code is for ggplot |
Server function of pptxList shiny module
pptxList( input, output, session, data = reactive(""), preprocessing = reactive("") )
pptxList( input, output, session, data = reactive(""), preprocessing = reactive("") )
input |
input |
output |
output |
session |
session |
data |
A data object |
preprocessing |
A character string of R code |
UI of pptxList shiny module
pptxListInput(id)
pptxListInput(id)
id |
A string |
library(shiny) library(ggplot2) library(editData) library(moonBook) library(readr) if(interactive()){ ui=fluidPage( pptxListInput("pptxlist") ) server=function(input,output,session){ mydf=callModule(pptxList,"pptxlist") } shinyApp(ui,server) }
library(shiny) library(ggplot2) library(editData) library(moonBook) library(readr) if(interactive()){ ui=fluidPage( pptxListInput("pptxlist") ) server=function(input,output,session){ mydf=callModule(pptxList,"pptxlist") } shinyApp(ui,server) }
Make a data.frame with character strings encoding R code
Rcode2df(result, eval = TRUE)
Rcode2df(result, eval = TRUE)
result |
character strings encoding R code |
eval |
logical. Whether or not evaluate the code |
Make a data.frame with character strings encoding R code
Rcode2df2(result, eval = TRUE)
Rcode2df2(result, eval = TRUE)
result |
character strings encoding R code |
eval |
logical. Whether or not evaluate the code |
Save R code to Microsoft Word format
Rcode2docx(...)
Rcode2docx(...)
... |
further arguments to be passed to plot2office |
## Not run: code="summary(lm(mpg~hp+wt,data=mtcars))" Rcode2docx(code=code,title="R code to Word") ## End(Not run)
## Not run: code="summary(lm(mpg~hp+wt,data=mtcars))" Rcode2docx(code=code,title="R code to Word") ## End(Not run)
Make a flextable object with character strings encoding R code
Rcode2flextable(result, format = "pptx", eval = TRUE)
Rcode2flextable(result, format = "pptx", eval = TRUE)
result |
character strings encoding R code |
format |
desired format. choices are "pptx" or "docx" |
eval |
logical. Whether or not evaluate the code |
Rcode2flextable("str(mtcars)\nsummary(mtcars)",eval=FALSE)
Rcode2flextable("str(mtcars)\nsummary(mtcars)",eval=FALSE)
Make R code slide
Rcode2office( code, preprocessing = "", title = "", type = "pptx", target = "Report", append = FALSE )
Rcode2office( code, preprocessing = "", title = "", type = "pptx", target = "Report", append = FALSE )
code |
A character string encoding R codes |
preprocessing |
A character string of R code as a preprocessing |
title |
A character |
type |
desired format. choices are "pptx" or "docx" |
target |
name of output file |
append |
logical |
## Not run: code="summary(lm(mpg~hp+wt,data=mtcars))" Rcode2office(code=code) ## End(Not run)
## Not run: code="summary(lm(mpg~hp+wt,data=mtcars))" Rcode2office(code=code) ## End(Not run)
Save R code to Microsoft Powerpoint format
Rcode2pptx(...)
Rcode2pptx(...)
... |
further arguments to be passed to plot2office |
## Not run: code="summary(lm(mpg~hp+wt,data=mtcars))" Rcode2pptx(code=code,title="R code to pptx") ## End(Not run)
## Not run: code="summary(lm(mpg~hp+wt,data=mtcars))" Rcode2pptx(code=code,title="R code to pptx") ## End(Not run)
Read comment from a file
readComment(filename, comment = "#")
readComment(filename, comment = "#")
filename |
A path for destination file |
comment |
A string used to identify comments |
Read a csv file with comment
readCSVComment(file)
readCSVComment(file)
file |
A path for destination file |
replace argument of a function
replace_argument(substring, argument, value)
replace_argument(substring, argument, value)
substring |
string of function call |
argument |
argument of function to be set |
value |
value to be set |
Convert numeric columns of data.frame to character
roundDf(df, digits = 2)
roundDf(df, digits = 2)
df |
A data.frame |
digits |
integer indicating the number of decimal places |
roundDf(iris,digits=c(1,2,3,4)) roundDf(mtcars,digits=2)
roundDf(iris,digits=c(1,2,3,4)) roundDf(mtcars,digits=2)
Sample data for pptxList A dataset containing five objects for reproducible research
sampleData2
sampleData2
A data frame with 5 rows and three columns
type of data
title of data
R code of data
Sample data for pptxList A dataset containing five objects for reproducible research
sampleData3
sampleData3
A data frame with 5 rows and three columns
type of data
title of data
text
R code of data
option for R code
set argument of a function
set_argument(code, argument, value = TRUE)
set_argument(code, argument, value = TRUE)
code |
string of function call |
argument |
argument of function to be set |
value |
value to be set |
code="df2flextable( ) " code="df2flextable(vanilla=TRUE,head(iris[1:10,]))" code="df2flextable(mtcars)" code="df2flextable(sampleData3)" code="df2flextable(head(iris[1:10,]),vanilla=TRUE)" set_argument(code,"vanilla",FALSE)
code="df2flextable( ) " code="df2flextable(vanilla=TRUE,head(iris[1:10,]))" code="df2flextable(mtcars)" code="df2flextable(sampleData3)" code="df2flextable(head(iris[1:10,]),vanilla=TRUE)" set_argument(code,"vanilla",FALSE)
Export data.frame or statistical output to Microsoft Word format
table2docx(...)
table2docx(...)
... |
further arguments to be passed to table2office |
## Not run: require(moonBook) x=mytable(Dx~.,data=acs) table2docx(x) table2docx(head(iris),title="head(iris)",append=TRUE,vanilla=FALSE) fit=lm(mpg~wt*hp,data=mtcars) table2docx(fit,title="Linear regression",append=TRUE,vanilla=TRUE) fit2=aov(yield ~ block + N * P + K, data = npk) table2docx(fit2,title="Linear regression",append=TRUE,vanilla=TRUE) ## End(Not run)
## Not run: require(moonBook) x=mytable(Dx~.,data=acs) table2docx(x) table2docx(head(iris),title="head(iris)",append=TRUE,vanilla=FALSE) fit=lm(mpg~wt*hp,data=mtcars) table2docx(fit,title="Linear regression",append=TRUE,vanilla=TRUE) fit2=aov(yield ~ block + N * P + K, data = npk) table2docx(fit2,title="Linear regression",append=TRUE,vanilla=TRUE) ## End(Not run)
Export data.frame or statistical output to a table in Microsoft Office
table2office( x = NULL, target = "Report", append = FALSE, title = "", vanilla = FALSE, echo = FALSE, add.rownames = TRUE, preprocessing = "", type = "pptx", landscape = FALSE, left = 1, top = 1 )
table2office( x = NULL, target = "Report", append = FALSE, title = "", vanilla = FALSE, echo = FALSE, add.rownames = TRUE, preprocessing = "", type = "pptx", landscape = FALSE, left = 1, top = 1 )
x |
An object or string |
target |
name of output file |
append |
logical value |
title |
Optional character of plot title |
vanilla |
A logical |
echo |
logical |
add.rownames |
logical |
preprocessing |
A character string |
type |
"pptx" or "docx" |
landscape |
logical |
left |
left margin |
top |
top margin |
Export data.frame or statistical output to Microsoft Powerpoint format
table2pptx(...)
table2pptx(...)
... |
further arguments to be passed to table2office |
## Not run: require(moonBook) x="mytable(Dx~.,data=acs)" table2pptx(x,title="mytable object",echo=TRUE) table2pptx("head(iris)",title="data.Frame",append=TRUE,vanilla=FALSE,echo=TRUE) x="fit<-lm(mpg~wt*hp,data=mtcars);fit" table2pptx(x,title="Linear regression",append=TRUE,vanilla=TRUE,echo=TRUE) fit2="aov(yield ~ block + N * P + K, data = npk)" table2pptx(fit2,title="ANOVA",append=TRUE,vanilla=TRUE,echo=TRUE) ## End(Not run)
## Not run: require(moonBook) x="mytable(Dx~.,data=acs)" table2pptx(x,title="mytable object",echo=TRUE) table2pptx("head(iris)",title="data.Frame",append=TRUE,vanilla=FALSE,echo=TRUE) x="fit<-lm(mpg~wt*hp,data=mtcars);fit" table2pptx(x,title="Linear regression",append=TRUE,vanilla=TRUE,echo=TRUE) fit2="aov(yield ~ block + N * P + K, data = npk)" table2pptx(fit2,title="ANOVA",append=TRUE,vanilla=TRUE,echo=TRUE) ## End(Not run)
Split strings with desired length with exdent
tensiSplit(string, size = 82, exdent = 3)
tensiSplit(string, size = 82, exdent = 3)
string |
String |
size |
desired length |
exdent |
exdent |
splitted character vector
Remove File and sink()
unsink(temp)
unsink(temp)
temp |
character file name |
Write a csv file with comment
writeCSVComment(data, file, metadata = "", comment = "#")
writeCSVComment(data, file, metadata = "", comment = "#")
data |
A data.frame |
file |
A path for destination file |
metadata |
A character string representing R codes as a preprocessing |
comment |
A string used to identify comments |
Make ztable with desired width
ztable2(df, cwidth = NULL, width = 80, ...)
ztable2(df, cwidth = NULL, width = 80, ...)
df |
a data.frame |
cwidth |
desired column width |
width |
desired table width in column |
... |
further argument to be passed to ztable() |
Convert ztable to flextable
ztable2flextable(z, ...)
ztable2flextable(z, ...)
z |
An object of class ztable |
... |
Further argument to be passed to df2flextable |
an object of class flextable