gganimate
gganimate copied to clipboard
unexplained error -- subscript out of bounds
I get the following error when I run anim_save:
> anim_save("state-testing.gif", animation=gp.anim)
Error in to[[1]] : subscript out of bounds
I will try to package this up in a smaller dataset so others can test, but in the meantime I wonder if anyone has odds about what might be the cause of an empty 'to' variable in this function. It seems as if there ought to be a check for that to make a more informative error message.
I'm using this with a map-making application. It's possible that there are different numbers of polygons in one frame and the next, as I believe the locations where the mapped data is zero are not drawn at all. Could that be the source of this issue? If so, perhaps this is a documentation request.
Thank you in advance, traceback here:
> traceback()
24: (function (from, to, enter, exit, min_n, closed = TRUE)
{
if (is.null(from)) {
if (is.null(enter)) {
from <- list(to[[1]][0, , drop = FALSE])
to <- from
}
else {
from <- lapply(to, function(x) {
x <- enter(x)
x$.phase <- "enter"
x
})
}
}
else if (is.null(to)) {
if (is.null(exit)) {
to <- list(from[[1]][0, , drop = FALSE])
from <- to
}
else {
to <- lapply(from, function(x) {
x <- exit(x)
x$.phase <- "exit"
x
})
}
}
else {
matched <- if (closed)
match_polygon(from, to, min_n)
else match_path(from, to, min_n)
from <- matched$from
to <- matched$to
}
from <- do.call(rbind, lapply(from, function(x) x[seq_len(nrow(x) +
1), ]))
to <- do.call(rbind, lapply(to, function(x) x[seq_len(nrow(x) +
1), ]))
from <- from[-nrow(from), ]
to <- to[-nrow(to), ]
list(from = from, to = to)
})(from = dots[[1L]][[311L]], to = dots[[2L]][[311L]], enter = NULL,
exit = function (x)
{
for (i in seq_along(factory_line)) {
x <- factory_line[[i]](x)
}
x
}, min_n = 50, closed = TRUE)
23: mapply(match_shapes, from = polygons$from, to = polygons$to,
MoreArgs = list(enter = enter, exit = exit, min_n = min_n,
closed = TRUE), SIMPLIFY = FALSE)
22: align_polygons(from, to, enter = enter, exit = exit, match = match)
21: transformr::tween_polygon(...)
20: transform_polygon(all_frames, states[[i]], ease, nframes[i],
!!id, enter, exit, match)
19: f(..., self = self)
18: self$expand_panel(data, type, id, match, ease, enter, exit, params,
layer_index)
17: FUN(X[[i]], ...)
16: lapply(split(data, data$PANEL), function(data) {
self$expand_panel(data, type, id, match, ease, enter, exit,
params, layer_index)
})
15: f(..., self = self)
14: self$expand_layer(data, type, id, match, ease, enter, exit, params,
layer_index)
13: (function (data, type, id, match, ease, enter, exit, layer_index)
{
self$expand_layer(data, type, id, match, ease, enter, exit,
params, layer_index)
})(data = dots[[1L]][[1L]], type = dots[[2L]][[1L]], id = dots[[3L]][[1L]],
match = dots[[4L]][[1L]], ease = dots[[5L]][[1L]], enter = dots[[6L]][[1L]],
exit = dots[[7L]][[1L]], layer_index = dots[[8L]][[1L]])
12: mapply(FUN = f, ..., SIMPLIFY = FALSE)
11: Map(function(data, type, id, match, ease, enter, exit, layer_index) {
self$expand_layer(data, type, id, match, ease, enter, exit,
params, layer_index)
}, data = data, type = type, id = id, match = match, ease = ease,
enter = enter, exit = exit, layer_index = layer_index)
10: f(..., self = self)
9: self$transition$expand_data(layer_data[tween_last], self$layer_type[tween_last],
self$group_column[tween_last], self$match_shape[tween_last],
ease, self$transmuters$enter_transmuters(tween_last), self$transmuters$exit_transmuters(tween_last),
self$transition_params, which(tween_last))
8: f(..., self = self)
7: scene$after_defaults(data)
6: ggplot_build.gganim(plot)
5: ggplot_build(plot)
4: prerender(plot, nframes_total)
3: animate.gganim(animation, ...)
2: animate(animation, ...)
1: anim_save("state-testing.gif", animation = gp.anim)
I get the same error while trying to plot a map with disease data over time. I am on a windows platform, with transformr_0.1.3 and gganimate_1.0.7 (R version 4.0.2 (2020-06-22).
Can either of you provide a reprex?