From 78fb2dcd263e58ca61815fc9853d83dd3fddb67a Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 12 May 2022 05:12:51 -0400 Subject: [PATCH] Fixes #263 add enum helpers for units and format --- NAMESPACE | 2 ++ R/tlf-env.R | 4 ++-- R/utilities-export.R | 29 +++++++++++++++++++++++------ man/AestheticProperties.Rd | 2 ++ man/Alignments.Rd | 2 ++ man/ExportFormats.Rd | 29 +++++++++++++++++++++++++++++ man/ExportUnits.Rd | 29 +++++++++++++++++++++++++++++ man/FontFaces.Rd | 2 ++ man/LegendPositions.Rd | 2 ++ man/Linetypes.Rd | 2 ++ man/Scaling.Rd | 2 ++ man/Shapes.Rd | 2 ++ man/tlfStatFunctions.Rd | 2 ++ 13 files changed, 101 insertions(+), 8 deletions(-) create mode 100644 man/ExportFormats.Rd create mode 100644 man/ExportUnits.Rd diff --git a/NAMESPACE b/NAMESPACE index ceadba76..87b4499e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -43,6 +43,8 @@ export(DDIComparisonTypes) export(DDIRatioDataMapping) export(DDIRatioPlotConfiguration) export(ExportConfiguration) +export(ExportFormats) +export(ExportUnits) export(Font) export(FontFaces) export(GroupMapping) diff --git a/R/tlf-env.R b/R/tlf-env.R index 007a810c..2918b06b 100644 --- a/R/tlf-env.R +++ b/R/tlf-env.R @@ -64,8 +64,8 @@ tlfEnv$defaultExportParameters <- list( #' @param name base file name of the exported plots #' @export setDefaultExportParameters <- function(format = NULL, width = NULL, height = NULL, units = NULL, dpi = NULL, name = NULL) { - validateIsString(format, nullAllowed = TRUE) - validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE) + validateIsIncluded(format, ExportFormats, nullAllowed = TRUE) + validateIsIncluded(units, ExportUnits, nullAllowed = TRUE) validateIsNumeric(width, nullAllowed = TRUE) validateIsNumeric(height, nullAllowed = TRUE) validateIsNumeric(dpi, nullAllowed = TRUE) diff --git a/R/utilities-export.R b/R/utilities-export.R index 1c0bafd4..94e14267 100644 --- a/R/utilities-export.R +++ b/R/utilities-export.R @@ -1,3 +1,20 @@ +#' @title ExportUnits +#' @import ospsuite.utils +#' @export +#' @description +#' List of all available units for `width` and `height` to export a ggplot object +#' @family enum helpers +ExportUnits <- enum(c("cm", "in", "mm", "px")) + + +#' @title ExportFormats +#' @import ospsuite.utils +#' @export +#' @description +#' List of all available formats to export a ggplot object +#' @family enum helpers +ExportFormats <- enum(c("png", "pdf", "eps", "ps", "tex", "jpeg", "tiff", "bmp", "svg", "wmf")) + #' @title setPlotExport #' @description Set plot export properties #' @param plotObject Graphical object created from ggplot @@ -12,8 +29,8 @@ setPlotExport <- function(plotObject, name = NULL, format = NULL, width = NULL, height = NULL, units = NULL, dpi = NULL) { validateIsOfType(plotObject, "ggplot") validateIsString(name, nullAllowed = TRUE) - validateIsString(format, nullAllowed = TRUE) - validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE) + validateIsIncluded(format, ExportFormats, nullAllowed = TRUE) + validateIsIncluded(units, ExportUnits, nullAllowed = TRUE) validateIsNumeric(width, nullAllowed = TRUE) validateIsNumeric(height, nullAllowed = TRUE) validateIsNumeric(dpi, nullAllowed = TRUE) @@ -34,7 +51,7 @@ setPlotExport <- function(plotObject, name = NULL, format = NULL, width = NULL, #' @export setPlotExportFormat <- function(plotObject, format = NULL) { validateIsOfType(plotObject, "ggplot") - validateIsString(format, nullAllowed = TRUE) + validateIsIncluded(format, ExportFormats, nullAllowed = TRUE) newPlotObject <- plotObject newPlotObject$plotConfiguration <- plotObject$plotConfiguration$clone(deep = TRUE) @@ -57,7 +74,7 @@ setPlotExportFormat <- function(plotObject, format = NULL) { #' @export setPlotExportDimensions <- function(plotObject, width = NULL, height = NULL, units = NULL, dpi = NULL) { validateIsOfType(plotObject, "ggplot") - validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE) + validateIsIncluded(units, ExportUnits, nullAllowed = TRUE) validateIsNumeric(width, nullAllowed = TRUE) validateIsNumeric(height, nullAllowed = TRUE) validateIsNumeric(dpi, nullAllowed = TRUE) @@ -93,8 +110,8 @@ exportPlot <- function(plotObject, fileName = NULL, name = NULL, format = NULL, validateIsOfType(plotObject, "ggplot") validateIsString(fileName, nullAllowed = TRUE) validateIsString(name, nullAllowed = TRUE) - validateIsString(format, nullAllowed = TRUE) - validateIsIncluded(units, c("cm", "in", "mm", "px"), nullAllowed = TRUE) + validateIsIncluded(format, ExportFormats, nullAllowed = TRUE) + validateIsIncluded(units, ExportUnits, nullAllowed = TRUE) validateIsNumeric(width, nullAllowed = TRUE) validateIsNumeric(height, nullAllowed = TRUE) validateIsNumeric(dpi, nullAllowed = TRUE) diff --git a/man/AestheticProperties.Rd b/man/AestheticProperties.Rd index 05fe415a..3baf4a08 100644 --- a/man/AestheticProperties.Rd +++ b/man/AestheticProperties.Rd @@ -16,6 +16,8 @@ Enum of aesthetic property names of \code{ggplot2} \seealso{ Other enum helpers: \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{LegendPositions}}, \code{\link{Linetypes}}, diff --git a/man/Alignments.Rd b/man/Alignments.Rd index 10eb87c8..89d226da 100644 --- a/man/Alignments.Rd +++ b/man/Alignments.Rd @@ -16,6 +16,8 @@ List of all available alignments/justifications for fonts \seealso{ Other enum helpers: \code{\link{AestheticProperties}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{LegendPositions}}, \code{\link{Linetypes}}, diff --git a/man/ExportFormats.Rd b/man/ExportFormats.Rd new file mode 100644 index 00000000..2c155f5b --- /dev/null +++ b/man/ExportFormats.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-export.R +\docType{data} +\name{ExportFormats} +\alias{ExportFormats} +\title{ExportFormats} +\format{ +An object of class \code{list} of length 10. +} +\usage{ +ExportFormats +} +\description{ +List of all available formats to export a ggplot object +} +\seealso{ +Other enum helpers: +\code{\link{AestheticProperties}}, +\code{\link{Alignments}}, +\code{\link{ExportUnits}}, +\code{\link{FontFaces}}, +\code{\link{LegendPositions}}, +\code{\link{Linetypes}}, +\code{\link{Scaling}}, +\code{\link{Shapes}}, +\code{\link{tlfStatFunctions}} +} +\concept{enum helpers} +\keyword{datasets} diff --git a/man/ExportUnits.Rd b/man/ExportUnits.Rd new file mode 100644 index 00000000..851c04fe --- /dev/null +++ b/man/ExportUnits.Rd @@ -0,0 +1,29 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utilities-export.R +\docType{data} +\name{ExportUnits} +\alias{ExportUnits} +\title{ExportUnits} +\format{ +An object of class \code{list} of length 4. +} +\usage{ +ExportUnits +} +\description{ +List of all available units for \code{width} and \code{height} to export a ggplot object +} +\seealso{ +Other enum helpers: +\code{\link{AestheticProperties}}, +\code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{FontFaces}}, +\code{\link{LegendPositions}}, +\code{\link{Linetypes}}, +\code{\link{Scaling}}, +\code{\link{Shapes}}, +\code{\link{tlfStatFunctions}} +} +\concept{enum helpers} +\keyword{datasets} diff --git a/man/FontFaces.Rd b/man/FontFaces.Rd index bc092113..1feb398a 100644 --- a/man/FontFaces.Rd +++ b/man/FontFaces.Rd @@ -17,6 +17,8 @@ List of all available font faces Other enum helpers: \code{\link{AestheticProperties}}, \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{LegendPositions}}, \code{\link{Linetypes}}, \code{\link{Scaling}}, diff --git a/man/LegendPositions.Rd b/man/LegendPositions.Rd index e7cf905c..ac2fb628 100644 --- a/man/LegendPositions.Rd +++ b/man/LegendPositions.Rd @@ -17,6 +17,8 @@ List of all available legend positions Other enum helpers: \code{\link{AestheticProperties}}, \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{Linetypes}}, \code{\link{Scaling}}, diff --git a/man/Linetypes.Rd b/man/Linetypes.Rd index d8b30aca..bbf20bcb 100644 --- a/man/Linetypes.Rd +++ b/man/Linetypes.Rd @@ -17,6 +17,8 @@ Enum of \code{ggplot2} linetypes Other enum helpers: \code{\link{AestheticProperties}}, \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{LegendPositions}}, \code{\link{Scaling}}, diff --git a/man/Scaling.Rd b/man/Scaling.Rd index b8ceef6c..dda62197 100644 --- a/man/Scaling.Rd +++ b/man/Scaling.Rd @@ -38,6 +38,8 @@ Scaling$date Other enum helpers: \code{\link{AestheticProperties}}, \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{LegendPositions}}, \code{\link{Linetypes}}, diff --git a/man/Shapes.Rd b/man/Shapes.Rd index 9177a660..df06cdf6 100644 --- a/man/Shapes.Rd +++ b/man/Shapes.Rd @@ -17,6 +17,8 @@ List of some \code{ggplot2} shapes Other enum helpers: \code{\link{AestheticProperties}}, \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{LegendPositions}}, \code{\link{Linetypes}}, diff --git a/man/tlfStatFunctions.Rd b/man/tlfStatFunctions.Rd index 69983d90..a71f3d63 100644 --- a/man/tlfStatFunctions.Rd +++ b/man/tlfStatFunctions.Rd @@ -18,6 +18,8 @@ To access the function from its name, use match.fun: e.g. testFun <- match.fun(" Other enum helpers: \code{\link{AestheticProperties}}, \code{\link{Alignments}}, +\code{\link{ExportFormats}}, +\code{\link{ExportUnits}}, \code{\link{FontFaces}}, \code{\link{LegendPositions}}, \code{\link{Linetypes}},