Skip to content

Commit 74e6960

Browse files
committed
Avoid assigning NULL to list, thereby deleting the element
1 parent b35cf63 commit 74e6960

File tree

1 file changed

+24
-16
lines changed

1 file changed

+24
-16
lines changed

R/coord-radial.R

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,18 @@ CoordRadial <- ggproto("CoordRadial", Coord,
250250
names(gdefs) <- aesthetics
251251

252252
# Train theta guide
253-
for (t in intersect(c("theta", "theta.sec"), aesthetics[!empty])) {
254-
gdefs[[t]] <- guides[[t]]$train(gdefs[[t]], panel_params[[t]])
255-
gdefs[[t]] <- guides[[t]]$transform(gdefs[[t]], self, panel_params)
256-
gdefs[[t]] <- guides[[t]]$get_layer_key(gdefs[[t]], layers)
257-
}
253+
t <- intersect(c("theta", "theta.sec"), aesthetics[!empty])
254+
gdefs[t] <- Map(
255+
function(guide, guide_param, scale) {
256+
guide_param$theme_suffix <- "theta"
257+
guide_param <- guide$train(guide_param, scale)
258+
guide_param <- guide$transform(guide_param, self, panel_params)
259+
guide_param <- guide$get_layer_key(guide_param, layers)
260+
},
261+
guide = guides[t],
262+
guide_param = gdefs[t],
263+
scale = panel_params[t]
264+
)
258265

259266
if (!isFALSE(self$r_axis_inside)) {
260267
# For radial axis, we need to pretend that rotation starts at 0 and
@@ -269,17 +276,18 @@ CoordRadial <- ggproto("CoordRadial", Coord,
269276
temp <- modify_list(panel_params, mod)
270277

271278
# Train radial guide
272-
for (r in intersect(c("r", "r.sec"), aesthetics[!empty])) {
273-
gdefs[[r]] <- guides[[r]]$train(gdefs[[r]], panel_params[[r]])
274-
gdefs[[r]] <- guides[[r]]$transform(gdefs[[r]], self, temp) # Use temp
275-
gdefs[[r]] <- guides[[r]]$get_layer_key(gdefs[[r]], layers)
276-
}
277-
278-
# Set theme suffixes
279-
gdefs$theta$theme_suffix <- "theta"
280-
gdefs$theta.sec$theme_suffix <- "theta"
281-
gdefs$r$theme_suffix <- "r"
282-
gdefs$r.sec$theme_suffix <- "r"
279+
r <- intersect(c("r", "r.sec"), aesthetics[!empty])
280+
gdefs[r] <- Map(
281+
function(guide, guide_param, scale) {
282+
guide_param$theme_suffix <- "r"
283+
guide_param <- guide$train(guide_param, scale)
284+
guide_param <- guide$transform(guide_param, self, temp)
285+
guide_param <- guide$get_layer_key(guide_param, layers)
286+
},
287+
guide = guides[r],
288+
guide_param = gdefs[r],
289+
scale = panel_params[r]
290+
)
283291

284292
panel_params$guides$update_params(gdefs)
285293
panel_params

0 commit comments

Comments
 (0)