Package 'tracee'

Title: Easily Save Output and Trace it Back to Code
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.
Authors: Philip Delff [aut, cre]
Maintainer: Philip Delff <[email protected]>
License: MIT + file LICENSE
Version: 0.0.4.901
Built: 2024-11-26 06:08:43 UTC
Source: https://github.com/philipdelff/tracee

Help Index


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

  • "standard" A powerpoint standard size, and two can be shown side by side - 7.2 by 5.4 in (WxH).

  • "wide" For a single wide plot on a powerpoint slide - 9.6 by 5.4 in

  • "A4" A full A4 page - 5.4 by 7.2 in

  • "square" As reads - 5.4 by 5.4 in

  • "wide-screen" For full screen display - 18.6 by 9 in

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()


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 script is provided. You can pass any string as time if you prefer a different format or a completely different string here instead (like model name?). Use time="" to omit.

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 file.

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 writeOutputs=TRUE/FALSE), if you use save=writeOutputs to comply with this.

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.