Type: | Package |
Title: | Easily Save Output and Trace it Back to Code |
Version: | 0.0.4 |
Maintainer: | Philip Delff <philip@delff.dk> |
Description: | Write output (plots and tables) ensuring traceability back to code. Includes a graphics saver with simple automation of stamping with source, destination and creation time. A list of plots can be saved at once. A user-friendly selection of output dimensions for presentations, on-screen inspections, and more available. |
License: | MIT + file LICENSE |
RoxygenNote: | 7.2.3 |
Depends: | R (≥ 4.0.0) |
Imports: | NMdata (≥ 0.0.14), data.table, ggplot2, grid, gridExtra, flextable |
Suggests: | knitr |
Encoding: | UTF-8 |
NeedsCompilation: | no |
Packaged: | 2024-01-08 14:35:39 UTC; philipde |
Author: | Philip Delff [aut, cre] |
Repository: | CRAN |
Date/Publication: | 2024-01-08 21:20:02 UTC |
Get predefined canvas sizes
Description
Get predefined canvas sizes
Usage
canvasSize(canvas, scale = 1, simplify = TRUE)
Arguments
canvas |
Can either be a character with one of the values
or it can be a list with elements width and height with single values (unit is inches). Example: canvas=list(height=5,width=9). |
scale |
A scale to apply to both directions of the canvas size. This can be useful in combination with the pre-defined canvas sizes. |
simplify |
If only one canvas returned and simplify=TRUE, the result will not be wrapped in a list. For programming, you most likely want simplify=FALSE to be sure to always get the same format back. |
Value
A list with numerical elements width and height as used by ggwrite.
See Also
Other Plotting:
ggstamp()
,
ggwater()
,
ggwrite()
Create a stamp with script path, output file path and time stamp in it.
Description
Create a stamp with script path, output file path and time stamp in it.
Usage
createStamp(script, file, time, addto)
Arguments
script |
The script path |
file |
the output file path |
time |
The default is to insert a time stamp taken from result of Sys.time(). Using the time argument you can overrule this by setting a fixed string instead. Use "" to omit. |
addto |
An existing caption to keep above the caption created by this function. |
Stamp and write flextab objects to one or multiple formats
Description
Stamp and write flextab objects to one or multiple formats
Usage
ftstamp(ft, file, script, bg = "#ffffff", time)
Arguments
ft |
a flextable object |
file |
The file that the flextable will be written to (no file is written by this function) |
script |
path to script - will be pasted as caption. |
bg |
Default bacground colour is #ffffff. |
time |
The default is to insert a time stamp taken from result of Sys.time(). Using the time argument you can overrule this by setting a fixed string instead. Use "" to omit. |
Stamp and write flextab objects to one or multiple formats
Description
Stamp and write flextab objects to one or multiple formats
Usage
ftwrite(ft, file, script, time, formats, save, quiet = FALSE, ...)
writeFlextab(ft, file, script, formats, save, quiet = FALSE, ...)
Arguments
ft |
A flextab object. |
file |
to save to. See formats to generate multiple files. |
script |
path to script - will be pasted as caption. If provided, a stamp will be included on the plot when writng file(s). |
time |
The default behavior is to include a time stamp if
|
formats |
One or more of png, docx, pptx, html. As a character vector. |
save |
Save the table to the given file or just show? Defaults to TRUE. Hint, if you use an "exportFlag", use save=exportFlag. |
quiet |
Default is false but use TRUE to suppress messages about what was saved. |
... |
Arguments passed to stampFlextab. |
Functions
-
writeFlextab
: Deprecated function name. Use ftwrite.
Always stamp your plots with script name
Description
This function is used to stamp ggplot type plots with datetime and script name. User must provide the script name.
Usage
ggstamp(plot, script = "", file, time = Sys.time())
Arguments
plot |
The plot to be stamped. |
script |
the script name. Date and time will be added automatically. |
file |
An optional output filename to be included in the stamp. |
time |
The timestamp to be included. |
Details
The stamp is adding using the caption label. If a caption is already in the plot, the stamp will be added in a new line.
The caption is derived as caption=paste(c(plot$label$caption,stamp,paste(date.txt,file)),collapse="\n")
ggplot 2.2.1 (which is years old) or newer is required.
Value
the plot with a stamp
A plot object with the stamp added as caption
See Also
Other Plotting:
canvasSize()
,
ggwater()
,
ggwrite()
Examples
library(ggplot2)
data(ChickWeight)
p1 <- ggplot(ChickWeight,aes(Time,weight,group=Chick,colour=factor(Diet)))+geom_line()
script <- "note"
ggstamp(p1,script)
## Or use ggwrite which will call ggstamp when the `script` argument is provided.
ggwrite(p1,script=script,canvas="wide")
Add watermarks to ggplots
Description
Add watermarks to ggplots
Usage
ggwater(text = "Not validated", scale = 1, rot = 30, col = "grey", alpha = 0.5)
Arguments
text |
What should be written on the plot |
scale |
the size |
rot |
rotation of the mark. Don't remember the unit. |
col |
the colour (a value, not an expression) of the watermark. Default is grey. |
alpha |
alpha value for the watermark. Default is 0.5. |
Details
This used to be based on https://www.r-bloggers.com/adding-watermarks-to-plots/ That solution stopped working, and this new solution is simpler and based on ggplot2 alone.
Value
a layer with a watermark that can be added to a plot
See Also
Other Plotting:
canvasSize()
,
ggstamp()
,
ggwrite()
Examples
library(ggplot2)
ff <- qplot(1:10, 11:20) + ggwater()
Export plots created with ggplot (and more) or tables to files (png or pdf) - or show them on screen.
Description
Export plots created with ggplot (and more) or tables to files (png or pdf) - or show them on screen.
Usage
ggwrite(
plot,
file,
script,
time,
canvas = "standard",
formats,
onefile = FALSE,
res = 200,
paper = "special",
save = TRUE,
show = !save,
useNames = FALSE,
quiet = FALSE
)
Arguments
plot |
A plot object or a list of plots. Normally generated with ggplot or qplot. But it can also be from grid.arrange or arrangeGrob with class gtable. That is experimental though. Not sure exactly what classes are supported. |
file |
A file to export to. Must end in .png or .pdf. If plot is a list, see onefile. If missing, plot is shown on screen. |
script |
This should normally be the path to your script. Requires ggplot >=2.2.1. |
time |
Passed to ggwrite. |
canvas |
Either a list of height and width or a shortname of predefined canvas size. See ?canvasSize. |
formats |
File formats to write to as a character
vector. Must be a subset of c("png","pdf"). Default is to only
write to the format matching the file name extension of
|
onefile |
Only applicable if plot is a list. If plot is a list and onefile=TRUE, all plots will be put in a pdf (file must end in pdf) with one plot per page. If plot is a list and onefile=FALSE, numbered files will be created - one per list element. |
res |
Resolution. Passed to png. |
paper |
Only used with pdf device. See ?pdf. |
save |
Save the plot to the given file or just show? Defaults
to TRUE. If a variable is used to control whether a script
generates outputs (say |
show |
Print the plot to the screen? Defaults to the opposite of save. Hint, combining save and show in knitr can give you both a high quality plot in your pdf and a png optimized for powerpoint. |
useNames |
If length(plot)>1 use names(plot) in the file names? Default is to use 1:length(plot). Only used if save is TRUE, and length(plot)>1. |
quiet |
Default is false but use TRUE to suppress messages about what was saved. |
Value
Nothing. Files written and/or plots shown, depending on argument values.
See Also
Other Plotting:
canvasSize()
,
ggstamp()
,
ggwater()
Examples
library(ggplot2)
writeOutput <- FALSE
data(ChickWeight)
p1 <- ggplot(ChickWeight,aes(Time,weight,group=Chick,colour=factor(Diet)))+geom_line()
ggwrite(p1) ## view plot on screen
script <- "note"
ggwrite(p1,script=script,canvas="wide",file="myplot1.png",save=writeOutput)
Stamp and write flextab objects to one or multiple formats
Description
Stamp and write flextab objects to one or multiple formats
Usage
stampFlextab(ft, file, script, bg = "#ffffff", time)
Arguments
ft |
a flextable object |
file |
The file that the flextable will be written to (no file is written by this function) |
script |
path to script - will be pasted as caption. |
bg |
Default bacground colour is #ffffff. |
time |
The default is to insert a time stamp taken from result of Sys.time(). Using the time argument you can overrule this by setting a fixed string instead. Use "" to omit. |