Skip to content

Commit 5141ef5

Browse files
authored
Use vctrs internally (#4868)
1 parent 7571122 commit 5141ef5

File tree

110 files changed

+728
-671
lines changed

Some content is hidden

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

110 files changed

+728
-671
lines changed

DESCRIPTION

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Imports:
4343
scales (>= 1.2.0),
4444
stats,
4545
tibble,
46+
vctrs (>= 0.4.1),
4647
withr (>= 2.0.0)
4748
Suggests:
4849
covr,
@@ -79,7 +80,7 @@ Config/testthat/edition: 3
7980
Encoding: UTF-8
8081
LazyData: true
8182
Roxygen: list(markdown = TRUE)
82-
RoxygenNote: 7.2.0
83+
RoxygenNote: 7.2.0.9000
8384
Collate:
8485
'ggproto.r'
8586
'ggplot-global.R'

NAMESPACE

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,20 @@ S3method("$",ggproto)
44
S3method("$",ggproto_parent)
55
S3method("$<-",uneval)
66
S3method("+",gg)
7-
S3method("[",mapped_discrete)
87
S3method("[",uneval)
9-
S3method("[<-",mapped_discrete)
108
S3method("[<-",uneval)
119
S3method("[[",ggproto)
1210
S3method("[[<-",uneval)
1311
S3method(.DollarNames,ggproto)
14-
S3method(as.data.frame,mapped_discrete)
1512
S3method(as.list,ggproto)
1613
S3method(autolayer,default)
1714
S3method(autoplot,default)
18-
S3method(c,mapped_discrete)
1915
S3method(drawDetails,zeroGrob)
2016
S3method(element_grob,element_blank)
2117
S3method(element_grob,element_line)
2218
S3method(element_grob,element_rect)
2319
S3method(element_grob,element_text)
20+
S3method(format,ggplot2_mapped_discrete)
2421
S3method(format,ggproto)
2522
S3method(format,ggproto_method)
2623
S3method(fortify,"NULL")
@@ -142,6 +139,30 @@ S3method(scale_type,sfc)
142139
S3method(single_value,default)
143140
S3method(single_value,factor)
144141
S3method(summary,ggplot)
142+
S3method(vec_arith,ggplot2_mapped_discrete)
143+
S3method(vec_arith.ggplot2_mapped_discrete,MISSING)
144+
S3method(vec_arith.ggplot2_mapped_discrete,default)
145+
S3method(vec_arith.ggplot2_mapped_discrete,ggplot2_mapped_discrete)
146+
S3method(vec_arith.ggplot2_mapped_discrete,numeric)
147+
S3method(vec_arith.numeric,ggplot2_mapped_discrete)
148+
S3method(vec_cast,character.ggplot2_mapped_discrete)
149+
S3method(vec_cast,double.ggplot2_mapped_discrete)
150+
S3method(vec_cast,factor.ggplot2_mapped_discrete)
151+
S3method(vec_cast,ggplot2_mapped_discrete.double)
152+
S3method(vec_cast,ggplot2_mapped_discrete.factor)
153+
S3method(vec_cast,ggplot2_mapped_discrete.ggplot2_mapped_discrete)
154+
S3method(vec_cast,ggplot2_mapped_discrete.integer)
155+
S3method(vec_cast,integer.ggplot2_mapped_discrete)
156+
S3method(vec_math,ggplot2_mapped_discrete)
157+
S3method(vec_ptype2,character.ggplot2_mapped_discrete)
158+
S3method(vec_ptype2,double.ggplot2_mapped_discrete)
159+
S3method(vec_ptype2,factor.ggplot2_mapped_discrete)
160+
S3method(vec_ptype2,ggplot2_mapped_discrete.character)
161+
S3method(vec_ptype2,ggplot2_mapped_discrete.double)
162+
S3method(vec_ptype2,ggplot2_mapped_discrete.factor)
163+
S3method(vec_ptype2,ggplot2_mapped_discrete.ggplot2_mapped_discrete)
164+
S3method(vec_ptype2,ggplot2_mapped_discrete.integer)
165+
S3method(vec_ptype2,integer.ggplot2_mapped_discrete)
145166
S3method(widthDetails,titleGrob)
146167
S3method(widthDetails,zeroGrob)
147168
export("%+%")
@@ -668,6 +689,7 @@ export(update_geom_defaults)
668689
export(update_labels)
669690
export(update_stat_defaults)
670691
export(vars)
692+
export(vec_arith.ggplot2_mapped_discrete)
671693
export(waiver)
672694
export(wrap_dims)
673695
export(xlab)
@@ -679,6 +701,7 @@ import(grid)
679701
import(gtable)
680702
import(rlang)
681703
import(scales)
704+
import(vctrs)
682705
importFrom(glue,glue)
683706
importFrom(glue,glue_collapse)
684707
importFrom(lifecycle,deprecated)

R/aes.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ rename_aes <- function(x) {
179179
names(x) <- standardise_aes_names(names(x))
180180
duplicated_names <- names(x)[duplicated(names(x))]
181181
if (length(duplicated_names) > 0L) {
182-
cli::cli_warn("Duplicated aesthetics after name standardisation: {.field {unique(duplicated_names)}}")
182+
cli::cli_warn("Duplicated aesthetics after name standardisation: {.field {unique0(duplicated_names)}}")
183183
}
184184
x
185185
}

R/annotation-custom.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,11 @@ GeomCustomAnn <- ggproto("GeomCustomAnn", Geom,
7373
if (!inherits(coord, "CoordCartesian")) {
7474
cli::cli_abort("{.fn annotation_custom} only works with {.fn coord_cartesian}")
7575
}
76-
corners <- new_data_frame(list(x = c(xmin, xmax), y = c(ymin, ymax)), n = 2)
76+
corners <- data_frame0(
77+
x = c(xmin, xmax),
78+
y = c(ymin, ymax),
79+
.size = 2
80+
)
7781
data <- coord$transform(corners, panel_params)
7882

7983
x_rng <- range(data$x, na.rm = TRUE)

R/annotation-logticks.r

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ GeomLogticks <- ggproto("GeomLogticks", Geom,
213213
}
214214
}
215215

216-
gTree(children = do.call("gList", ticks))
216+
gTree(children = inject(gList(!!!ticks)))
217217
},
218218

219219
default_aes = aes(colour = "black", size = 0.5, linetype = 1, alpha = 1)
@@ -254,7 +254,12 @@ calc_logticks <- function(base = 10, ticks_per_base = base - 1,
254254
longtick_after_base <- floor(ticks_per_base/2)
255255
tickend[ cycleIdx == longtick_after_base ] <- midend
256256

257-
tickdf <- new_data_frame(list(value = ticks, start = start, end = tickend), n = length(ticks))
257+
tickdf <- data_frame0(
258+
value = ticks,
259+
start = start,
260+
end = tickend,
261+
.size = length(ticks)
262+
)
258263

259264
return(tickdf)
260265
}

R/annotation-map.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ GeomAnnotationMap <- ggproto("GeomAnnotationMap", GeomMap,
9393
# must be sequential integers
9494
coords <- coord_munch(coord, map, panel_params)
9595
coords$group <- coords$group %||% coords$id
96-
grob_id <- match(coords$group, unique(coords$group))
96+
grob_id <- match(coords$group, unique0(coords$group))
9797

9898
polygonGrob(coords$x, coords$y, default.units = "native",
9999
id = grob_id,

R/annotation-raster.r

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ GeomRasterAnn <- ggproto("GeomRasterAnn", Geom,
7676
if (!inherits(coord, "CoordCartesian")) {
7777
cli::cli_abort("{.fn annotation_raster} only works with {.fn coord_cartesian}")
7878
}
79-
corners <- new_data_frame(list(x = c(xmin, xmax), y = c(ymin, ymax)), n = 2)
79+
corners <- data_frame0(
80+
x = c(xmin, xmax),
81+
y = c(ymin, ymax),
82+
.size = 2
83+
)
8084
data <- coord$transform(corners, panel_params)
8185

8286
x_rng <- range(data$x, na.rm = TRUE)

R/annotation.r

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
5757

5858
# Check that all aesthetic have compatible lengths
5959
lengths <- vapply(aesthetics, length, integer(1))
60-
n <- unique(lengths)
60+
n <- unique0(lengths)
6161

6262
# if there is more than one unique length, ignore constants
6363
if (length(n) > 1L) {
@@ -71,7 +71,7 @@ annotate <- function(geom, x = NULL, y = NULL, xmin = NULL, xmax = NULL,
7171
cli::cli_abort("Unequal parameter lengths: {details}")
7272
}
7373

74-
data <- new_data_frame(position, n = n)
74+
data <- data_frame0(!!!position, .size = n)
7575
layer(
7676
geom = geom,
7777
params = list(

R/axis-secondary.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ AxisSecondary <- ggproto("AxisSecondary", NULL,
193193
full_range <- self$transform_range(old_range)
194194

195195
# Test for monotonicity
196-
if (length(unique(sign(diff(full_range)))) != 1)
196+
if (length(unique0(sign(diff(full_range)))) != 1)
197197
cli::cli_abort("Transformation for secondary axes must be monotonic")
198198
},
199199

R/bench.r

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ benchplot <- function(x) {
2626
times <- rbind(construct, build, render, draw)[, 1:3]
2727
times <- rbind(times, colSums(times))
2828

29-
cbind(
29+
vec_cbind(
3030
step = c("construct", "build", "render", "draw", "TOTAL"),
3131
mat_2_df(times)
3232
)

0 commit comments

Comments
 (0)