Skip to content

Commit 5e4a6ef

Browse files
authored
Treat data as list during position transformation (#3002)
* Treat input as list * Add bullet to vignette * Make note about changes related to performance
1 parent 2e9ceb7 commit 5e4a6ef

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

R/position-.r

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ Position <- ggproto("Position",
7575
#' @keywords internal
7676
#' @export
7777
transform_position <- function(df, trans_x = NULL, trans_y = NULL, ...) {
78+
# Treat df as list during transformation for faster set/get
79+
oldclass <- class(df)
80+
df <- unclass(df)
7881
scales <- aes_to_scale(names(df))
7982

8083
if (!is.null(trans_x)) {
@@ -84,5 +87,7 @@ transform_position <- function(df, trans_x = NULL, trans_y = NULL, ...) {
8487
df[scales == "y"] <- lapply(df[scales == "y"], trans_y, ...)
8588
}
8689

90+
class(df) <- oldclass
91+
8792
df
8893
}

vignettes/profiling.Rmd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ are summarised below:
6767
and will just lead to slower code. The `data.frame()` call is now only used
6868
when dealing with output from other packages where the extra safety is a
6969
benefit.
70+
- **Speed up position transformation** The `transform_position` helper was
71+
unreasonably slow due to the slowness of getting and assigning columns in
72+
data.frame. The input is now treated as a list during transformation.

0 commit comments

Comments
 (0)