Skip to content

Commit a13b934

Browse files
authored
make tlf ggplot2 4.0.0 compatible (#530)
* make tlf ggplot2 4.0.0 compatible * add GitHub Actions workflow * update jobs dependencies * disable pkgdown job * Add Remotes field for dependencies resolution * Add devtools as dev dependency (Suggest) * ignore .github in R build * Set seed before rnorm to make snapshot consistent * Remove AppVeyor related files * Increment version number to 1.6.1 * devtools::document() * remove upper cap on ggplot2 version
1 parent fa42f58 commit a13b934

File tree

79 files changed

+915
-477
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+915
-477
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ tests\^spelling
3232
^\.lintr$
3333
^WIP/.
3434
^old/.
35+
^.github/.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Main-Workflow
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions: write-all
10+
11+
jobs:
12+
R-CMD-Check:
13+
if: ${{ !cancelled() }}
14+
uses: Open-Systems-Pharmacology/Workflows/.github/workflows/R-CMD-check-build.yaml@main
15+
16+
test-coverage:
17+
if: ${{ !cancelled() }}
18+
uses: Open-Systems-Pharmacology/Workflows/.github/workflows/test-coverage.yaml@main
19+
secrets:
20+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

.gitmodules

Lines changed: 0 additions & 3 deletions
This file was deleted.

DESCRIPTION

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: tlf
22
Type: Package
33
Title: TLF Library
4-
Version: 1.6.0
4+
Version: 1.6.1
55
Authors@R:
66
c(person(given = "Open-Systems-Pharmacology Community",
77
role = "cph"),
@@ -31,7 +31,6 @@ URL: https://github.com/open-systems-pharmacology/tlf-library
3131
BugReports: https://github.com/open-systems-pharmacology/tlf-library/issues
3232
Imports:
3333
ggplot2 (>= 3.3.0),
34-
ggplot2 (< 4.0.0),
3534
R6,
3635
jsonlite,
3736
ospsuite.utils (>= 1.6.0),
@@ -42,6 +41,8 @@ Imports:
4241
lifecycle
4342
Depends:
4443
R (>= 4.1)
44+
Remotes:
45+
ospsuite.utils=Open-Systems-Pharmacology/OSPSuite.RUtils
4546
Encoding: UTF-8
4647
RoxygenNote: 7.3.3
4748
Roxygen: list(markdown = TRUE)
@@ -55,7 +56,8 @@ Suggests:
5556
sysfonts,
5657
svglite,
5758
testthat (>= 3.0.3),
58-
vdiffr (>= 1.0.0)
59+
vdiffr (>= 1.0.0),
60+
devtools
5961
VignetteBuilder: knitr
6062
Collate:
6163
'aaa-utilities.R'

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# tlf 1.6.1
2+
3+
- Hot fixes following ggplot2 v4.0.0 breaking changes.
4+
15
# tlf 1.6.0
26

37
- Lower Limit Of Quantification (LLOQ) can be added on time-profile plots and obs-vs-pred plots.

R/aaa-utilities.R

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,10 @@
8585
plotConfiguration = NULL) {
8686
plotObject <- plotObject %||% initializePlot(plotConfiguration)
8787
validateIsOfType(plotObject, "ggplot")
88-
validateIsIncluded("plotConfiguration", names(plotObject))
88+
# Check if plotConfiguration attribute exists (ggplot2 4.0.0 compatibility)
89+
if (is.null(plotObject$plotConfiguration)) {
90+
stop("plotConfiguration attribute is missing from the plot object")
91+
}
8992
return(plotObject)
9093
}
9194

R/font.R

Lines changed: 78 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,33 @@ Font <- R6::R6Class(
3232
#' @param maxWidth numeric that will be converted to a ggplot2::unit object (in "pt" unit) defining the maximum width of text box.
3333
#' @param margin a numeric vector of length 4 defining the size of the area (in pt) around the text in the followin order: top, right, bottom, left.
3434
#' @return A new `Font` object
35-
initialize = function(color = NULL,
36-
size = NULL,
37-
fontFamily = NULL,
38-
fontFace = NULL,
39-
angle = NULL,
40-
align = NULL,
41-
maxWidth = NULL,
42-
margin = NULL) {
35+
initialize = function(
36+
color = NULL,
37+
size = NULL,
38+
fontFamily = NULL,
39+
fontFace = NULL,
40+
angle = NULL,
41+
align = NULL,
42+
maxWidth = NULL,
43+
margin = NULL
44+
) {
4345
validateIsString(c(color, fontFamily), nullAllowed = TRUE)
4446
validateIsNumeric(c(size, angle), nullAllowed = TRUE)
4547
validateIsIncluded(fontFace, FontFaces, nullAllowed = TRUE)
4648
validateIsIncluded(align, Alignments, nullAllowed = TRUE)
47-
eval(.parseVariableToObject("self", c("size", "color", "fontFace", "fontFamily", "angle", "align", "maxWidth"), keepIfNull = TRUE))
49+
eval(.parseVariableToObject(
50+
"self",
51+
c(
52+
"size",
53+
"color",
54+
"fontFace",
55+
"fontFamily",
56+
"angle",
57+
"align",
58+
"maxWidth"
59+
),
60+
keepIfNull = TRUE
61+
))
4862
},
4963

5064
#' @description Create a `ggplot2::element_text` directly convertible by `ggplot2::theme`.
@@ -56,16 +70,32 @@ Font <- R6::R6Class(
5670
#' @param align character defining the alignment of font as defined in helper enum `Alignments`.
5771
#' @param margin a numeric vector of length 4 defining the size of the area (in pt) around the text in the followin order: top, right, bottom, left.
5872
#' @return An `element_text` object.
59-
createPlotTextFont = function(size = NULL,
60-
color = NULL,
61-
fontFamily = NULL,
62-
fontFace = NULL,
63-
angle = NULL,
64-
align = NULL,
65-
margin = NULL) {
73+
createPlotTextFont = function(
74+
size = NULL,
75+
color = NULL,
76+
fontFamily = NULL,
77+
fontFace = NULL,
78+
angle = NULL,
79+
align = NULL,
80+
margin = NULL
81+
) {
6682
margin <- margin %||% self$margin
6783
if (!is.null(margin)) {
68-
margin <- ggplot2::unit(margin, "pt")
84+
# Ensure margin is a vector of length 4 (top, right, bottom, left)
85+
if (length(margin) == 1) {
86+
margin <- rep(margin, 4)
87+
} else if (length(margin) == 2) {
88+
margin <- rep(margin, 2)
89+
} else if (length(margin) == 3) {
90+
margin <- c(margin, margin[2])
91+
}
92+
margin <- ggplot2::margin(
93+
t = margin[1],
94+
r = margin[2],
95+
b = margin[3],
96+
l = margin[4],
97+
unit = "pt"
98+
)
6999
}
70100

71101
ggplot2::element_text(
@@ -76,7 +106,8 @@ Font <- R6::R6Class(
76106
family = .checkPlotFontFamily(fontFamily %||% self$fontFamily),
77107
angle = angle %||% self$angle,
78108
vjust = 0.5,
79-
hjust = switch(align %||% self$align,
109+
hjust = switch(
110+
align %||% self$align,
80111
"left" = 0,
81112
"center" = 0.5,
82113
"right" = 1
@@ -94,21 +125,37 @@ Font <- R6::R6Class(
94125
#' @param maxWidth numeric that will be converted to a ggplot2::unit object (in "pt" unit) defining the maximum width of text box.
95126
#' @param margin a numeric vector of length 4 defining the size of the area (in pt) around the text in the followin order: top, right, bottom, left.
96127
#' @return An `ggtext::element_textbox` object.
97-
createPlotTextBoxFont = function(size = NULL,
98-
color = NULL,
99-
fontFamily = NULL,
100-
fontFace = NULL,
101-
angle = NULL,
102-
align = NULL,
103-
maxWidth = NULL,
104-
margin = NULL) {
128+
createPlotTextBoxFont = function(
129+
size = NULL,
130+
color = NULL,
131+
fontFamily = NULL,
132+
fontFace = NULL,
133+
angle = NULL,
134+
align = NULL,
135+
maxWidth = NULL,
136+
margin = NULL
137+
) {
105138
maxWidth <- maxWidth %||% self$maxWidth
106139
if (!is.null(maxWidth)) {
107140
maxWidth <- ggplot2::unit(maxWidth, "pt")
108141
}
109142
margin <- margin %||% self$margin
110143
if (!is.null(margin)) {
111-
margin <- ggplot2::unit(margin, "pt")
144+
# Ensure margin is a vector of length 4 (top, right, bottom, left)
145+
if (length(margin) == 1) {
146+
margin <- rep(margin, 4)
147+
} else if (length(margin) == 2) {
148+
margin <- rep(margin, 2)
149+
} else if (length(margin) == 3) {
150+
margin <- c(margin, margin[2])
151+
}
152+
margin <- ggplot2::margin(
153+
t = margin[1],
154+
r = margin[2],
155+
b = margin[3],
156+
l = margin[4],
157+
unit = "pt"
158+
)
112159
}
113160

114161
ggtext::element_textbox_simple(
@@ -119,7 +166,8 @@ Font <- R6::R6Class(
119166
family = .checkPlotFontFamily(fontFamily %||% self$fontFamily),
120167
orientation = .convertAngleToOrientation(angle %||% self$angle),
121168
valign = 0.5,
122-
halign = switch(align %||% self$align,
169+
halign = switch(
170+
align %||% self$align,
123171
"left" = 0,
124172
"center" = 0.5,
125173
"right" = 1
@@ -161,7 +209,8 @@ Font <- R6::R6Class(
161209
.convertAngleToOrientation <- function(angle) {
162210
# use modulo 360 to in case minus angles were provided
163211
return(
164-
switch(as.character(angle %% 360),
212+
switch(
213+
as.character(angle %% 360),
165214
"0" = "upright",
166215
"90" = "left-rotated",
167216
"180" = "right-rotated",

R/plot-grid.R

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,16 @@ plotGrid <- function(plotGridConfiguration) {
104104
valign = plotGridConfiguration$titleVerticalJustification,
105105
hjust = plotGridConfiguration$captionHorizontalJustification,
106106
vjust = plotGridConfiguration$captionVerticalJustification,
107-
orientation = .convertAngleToOrientation(plotGridConfiguration$titleAngle),
108-
margin = ggplot2::unit(plotGridConfiguration$titleMargin, "pt")
107+
orientation = .convertAngleToOrientation(
108+
plotGridConfiguration$titleAngle
109+
),
110+
margin = ggplot2::margin(
111+
t = plotGridConfiguration$titleMargin[1],
112+
r = plotGridConfiguration$titleMargin[2],
113+
b = plotGridConfiguration$titleMargin[3],
114+
l = plotGridConfiguration$titleMargin[4],
115+
unit = "pt"
116+
)
109117
),
110118
plot.subtitle = ggtext::element_textbox_simple(
111119
color = plotGridConfiguration$subtitleColor,
@@ -116,8 +124,16 @@ plotGrid <- function(plotGridConfiguration) {
116124
valign = plotGridConfiguration$subtitleVerticalJustification,
117125
hjust = plotGridConfiguration$captionHorizontalJustification,
118126
vjust = plotGridConfiguration$captionVerticalJustification,
119-
orientation = .convertAngleToOrientation(plotGridConfiguration$subtitleAngle),
120-
margin = ggplot2::unit(plotGridConfiguration$subtitleMargin, "pt")
127+
orientation = .convertAngleToOrientation(
128+
plotGridConfiguration$subtitleAngle
129+
),
130+
margin = ggplot2::margin(
131+
t = plotGridConfiguration$subtitleMargin[1],
132+
r = plotGridConfiguration$subtitleMargin[2],
133+
b = plotGridConfiguration$subtitleMargin[3],
134+
l = plotGridConfiguration$subtitleMargin[4],
135+
unit = "pt"
136+
)
121137
),
122138
plot.caption = ggtext::element_textbox_simple(
123139
color = plotGridConfiguration$captionColor,
@@ -128,8 +144,16 @@ plotGrid <- function(plotGridConfiguration) {
128144
valign = plotGridConfiguration$captionVerticalJustification,
129145
hjust = plotGridConfiguration$captionHorizontalJustification,
130146
vjust = plotGridConfiguration$captionVerticalJustification,
131-
orientation = .convertAngleToOrientation(plotGridConfiguration$captionAngle),
132-
margin = ggplot2::unit(plotGridConfiguration$captionMargin, "pt")
147+
orientation = .convertAngleToOrientation(
148+
plotGridConfiguration$captionAngle
149+
),
150+
margin = ggplot2::margin(
151+
t = plotGridConfiguration$captionMargin[1],
152+
r = plotGridConfiguration$captionMargin[2],
153+
b = plotGridConfiguration$captionMargin[3],
154+
l = plotGridConfiguration$captionMargin[4],
155+
unit = "pt"
156+
)
133157
)
134158
)
135159
) &
@@ -330,7 +354,6 @@ PlotGridConfiguration <- R6::R6Class(
330354
captionAngle = 0,
331355
captionMargin = c(2, 2, 5, 2),
332356

333-
334357
# arrangement ------------------------------------
335358

336359
nColumns = NULL,
@@ -427,16 +450,36 @@ PlotGridConfiguration <- R6::R6Class(
427450
private$printLine("\tCaption", self$caption, addTab = TRUE)
428451

429452
private$printLine("Plot grid arrangement", addTab = TRUE)
430-
private$printLine("\tNumber of plots included", length(self$plotList), addTab = TRUE)
431-
private$printLine("\tNumber of columns in the grid", self$nColumns, addTab = TRUE)
432-
private$printLine("\tNumber of rows in the grid", self$nRows, addTab = TRUE)
433-
private$printLine("\tArranged in row-major order", self$byRow, addTab = TRUE)
453+
private$printLine(
454+
"\tNumber of plots included",
455+
length(self$plotList),
456+
addTab = TRUE
457+
)
458+
private$printLine(
459+
"\tNumber of columns in the grid",
460+
self$nColumns,
461+
addTab = TRUE
462+
)
463+
private$printLine(
464+
"\tNumber of rows in the grid",
465+
self$nRows,
466+
addTab = TRUE
467+
)
468+
private$printLine(
469+
"\tArranged in row-major order",
470+
self$byRow,
471+
addTab = TRUE
472+
)
434473

435474
private$printLine("Individual plot tags", addTab = TRUE)
436475
private$printLine("\tTag level format", self$tagLevels, addTab = TRUE)
437476
private$printLine("\tTag level prefix", self$tagPrefix, addTab = TRUE)
438477
private$printLine("\tTag level suffix", self$tagSuffix, addTab = TRUE)
439-
private$printLine("\tTag level separator", self$tagSeparator, addTab = TRUE)
478+
private$printLine(
479+
"\tTag level separator",
480+
self$tagSeparator,
481+
addTab = TRUE
482+
)
440483
}
441484
)
442485
)

0 commit comments

Comments
 (0)