Use recycling to pad the end of a list of data frames where data frame elements in the list repeat in a cyclical pattern.

pad_frames(x, id, n.period = 360, rotation = "add", force = TRUE)

Arguments

x

list of data frames.

id

character, column name referring to column of x representing frame sequence integer IDs.

n.period

An integer, the known period of rotation that will be part of an animation in which the map data frames in x will be sequentially plotted over. Default is 360 (1-degree increment rotations).

rotation

character, one of "add" or "pad".

force

When the length of x is greater than or equal to n.period still force padding to occur. Defaults to TRUE. Otherwise return x.

Value

returns x but padded with it's final element appended repeatedly based on a specified period and type of padding method.

Details

pad_frames is used on lists of data frames where sequence of data frames contains content that repeats over the list. It is used in cases where the data frames contain map data (long, lat, and z), for example describing the visible hemisphere surface of a rotating globe. The number of iterations in a full rotation may not be factorable by the length of the time series of map data (length of list). For example, a rotating globe animation may complete 10 rotations with 60 frames per rotation, using 600 frames total, but the list x may contain 550 data frames. With rotation="pad", the last data frame in x is recycled to pad the series out to 600 frames so that the animation can display and "hang" on the terminal map data set until a final complete rotation is completed. With rotation="add", a full period is added to the end of the x rather than padding only far enough to make the length of the data series factorable by the rotation period length.

Examples

library(dplyr) library(purrr) data(annualtemps) x <- map(1:4, ~mutate(filter(annualtemps, Year-2009==.x), idx=.x)) n <- 6 pad_frames(x, id="idx", n.period=n, rotation="add")
#> [[1]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2010 1.09 1 #> 2 -177. 67.0 2010 3.21 1 #> 3 -177. 73.7 2010 2.76 1 #> 4 -170 53.7 2010 0.91 1 #> 5 -170 60.3 2010 2.47 1 #> 6 -170 67.0 2010 2.73 1 #> 7 -163. 20.3 2010 0.19 1 #> 8 -163. 53.7 2010 0.79 1 #> 9 -163. 60.3 2010 1.43 1 #> 10 -163. 67.0 2010 1.28 1 #> # ... with 602 more rows #> #> [[2]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2011 0.570 2 #> 2 -177. 67.0 2011 2.52 2 #> 3 -177. 73.7 2011 1.93 2 #> 4 -170 53.7 2011 0.67 2 #> 5 -170 60.3 2011 2.65 2 #> 6 -170 67.0 2011 2.73 2 #> 7 -163. 20.3 2011 0.99 2 #> 8 -163. 53.7 2011 1.37 2 #> 9 -163. 60.3 2011 3.01 2 #> 10 -163. 67.0 2011 2.78 2 #> # ... with 602 more rows #> #> [[3]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2012 -0.25 3 #> 2 -177. 67.0 2012 2.04 3 #> 3 -177. 73.7 2012 2 3 #> 4 -170 53.7 2012 0.23 3 #> 5 -170 60.3 2012 1.02 3 #> 6 -170 67.0 2012 1.56 3 #> 7 -163. 20.3 2012 0.79 3 #> 8 -163. 53.7 2012 0.7 3 #> 9 -163. 60.3 2012 1.47 3 #> 10 -163. 67.0 2012 1.91 3 #> # ... with 602 more rows #> #> [[4]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 4 #> 2 -177. 67.0 2013 2.46 4 #> 3 -177. 73.7 2013 2.09 4 #> 4 -170 53.7 2013 1.38 4 #> 5 -170 60.3 2013 2.26 4 #> 6 -170 67.0 2013 2.44 4 #> 7 -163. 20.3 2013 0.28 4 #> 8 -163. 53.7 2013 1.64 4 #> 9 -163. 60.3 2013 2.06 4 #> 10 -163. 67.0 2013 2.09 4 #> # ... with 602 more rows #> #> [[5]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 5 #> 2 -177. 67.0 2013 2.46 5 #> 3 -177. 73.7 2013 2.09 5 #> 4 -170 53.7 2013 1.38 5 #> 5 -170 60.3 2013 2.26 5 #> 6 -170 67.0 2013 2.44 5 #> 7 -163. 20.3 2013 0.28 5 #> 8 -163. 53.7 2013 1.64 5 #> 9 -163. 60.3 2013 2.06 5 #> 10 -163. 67.0 2013 2.09 5 #> # ... with 602 more rows #> #> [[6]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 6 #> 2 -177. 67.0 2013 2.46 6 #> 3 -177. 73.7 2013 2.09 6 #> 4 -170 53.7 2013 1.38 6 #> 5 -170 60.3 2013 2.26 6 #> 6 -170 67.0 2013 2.44 6 #> 7 -163. 20.3 2013 0.28 6 #> 8 -163. 53.7 2013 1.64 6 #> 9 -163. 60.3 2013 2.06 6 #> 10 -163. 67.0 2013 2.09 6 #> # ... with 602 more rows #> #> [[7]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 7 #> 2 -177. 67.0 2013 2.46 7 #> 3 -177. 73.7 2013 2.09 7 #> 4 -170 53.7 2013 1.38 7 #> 5 -170 60.3 2013 2.26 7 #> 6 -170 67.0 2013 2.44 7 #> 7 -163. 20.3 2013 0.28 7 #> 8 -163. 53.7 2013 1.64 7 #> 9 -163. 60.3 2013 2.06 7 #> 10 -163. 67.0 2013 2.09 7 #> # ... with 602 more rows #> #> [[8]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 8 #> 2 -177. 67.0 2013 2.46 8 #> 3 -177. 73.7 2013 2.09 8 #> 4 -170 53.7 2013 1.38 8 #> 5 -170 60.3 2013 2.26 8 #> 6 -170 67.0 2013 2.44 8 #> 7 -163. 20.3 2013 0.28 8 #> 8 -163. 53.7 2013 1.64 8 #> 9 -163. 60.3 2013 2.06 8 #> 10 -163. 67.0 2013 2.09 8 #> # ... with 602 more rows #> #> [[9]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 9 #> 2 -177. 67.0 2013 2.46 9 #> 3 -177. 73.7 2013 2.09 9 #> 4 -170 53.7 2013 1.38 9 #> 5 -170 60.3 2013 2.26 9 #> 6 -170 67.0 2013 2.44 9 #> 7 -163. 20.3 2013 0.28 9 #> 8 -163. 53.7 2013 1.64 9 #> 9 -163. 60.3 2013 2.06 9 #> 10 -163. 67.0 2013 2.09 9 #> # ... with 602 more rows #>
pad_frames(x, id="idx", n.period=n, rotation="pad")
#> [[1]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2010 1.09 1 #> 2 -177. 67.0 2010 3.21 1 #> 3 -177. 73.7 2010 2.76 1 #> 4 -170 53.7 2010 0.91 1 #> 5 -170 60.3 2010 2.47 1 #> 6 -170 67.0 2010 2.73 1 #> 7 -163. 20.3 2010 0.19 1 #> 8 -163. 53.7 2010 0.79 1 #> 9 -163. 60.3 2010 1.43 1 #> 10 -163. 67.0 2010 1.28 1 #> # ... with 602 more rows #> #> [[2]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2011 0.570 2 #> 2 -177. 67.0 2011 2.52 2 #> 3 -177. 73.7 2011 1.93 2 #> 4 -170 53.7 2011 0.67 2 #> 5 -170 60.3 2011 2.65 2 #> 6 -170 67.0 2011 2.73 2 #> 7 -163. 20.3 2011 0.99 2 #> 8 -163. 53.7 2011 1.37 2 #> 9 -163. 60.3 2011 3.01 2 #> 10 -163. 67.0 2011 2.78 2 #> # ... with 602 more rows #> #> [[3]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2012 -0.25 3 #> 2 -177. 67.0 2012 2.04 3 #> 3 -177. 73.7 2012 2 3 #> 4 -170 53.7 2012 0.23 3 #> 5 -170 60.3 2012 1.02 3 #> 6 -170 67.0 2012 1.56 3 #> 7 -163. 20.3 2012 0.79 3 #> 8 -163. 53.7 2012 0.7 3 #> 9 -163. 60.3 2012 1.47 3 #> 10 -163. 67.0 2012 1.91 3 #> # ... with 602 more rows #> #> [[4]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 4 #> 2 -177. 67.0 2013 2.46 4 #> 3 -177. 73.7 2013 2.09 4 #> 4 -170 53.7 2013 1.38 4 #> 5 -170 60.3 2013 2.26 4 #> 6 -170 67.0 2013 2.44 4 #> 7 -163. 20.3 2013 0.28 4 #> 8 -163. 53.7 2013 1.64 4 #> 9 -163. 60.3 2013 2.06 4 #> 10 -163. 67.0 2013 2.09 4 #> # ... with 602 more rows #> #> [[5]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 5 #> 2 -177. 67.0 2013 2.46 5 #> 3 -177. 73.7 2013 2.09 5 #> 4 -170 53.7 2013 1.38 5 #> 5 -170 60.3 2013 2.26 5 #> 6 -170 67.0 2013 2.44 5 #> 7 -163. 20.3 2013 0.28 5 #> 8 -163. 53.7 2013 1.64 5 #> 9 -163. 60.3 2013 2.06 5 #> 10 -163. 67.0 2013 2.09 5 #> # ... with 602 more rows #> #> [[6]] #> # A tibble: 612 x 5 #> lon lat Year z idx #> <dbl> <dbl> <int> <dbl> <int> #> 1 -177. 53.7 2013 0.85 6 #> 2 -177. 67.0 2013 2.46 6 #> 3 -177. 73.7 2013 2.09 6 #> 4 -170 53.7 2013 1.38 6 #> 5 -170 60.3 2013 2.26 6 #> 6 -170 67.0 2013 2.44 6 #> 7 -163. 20.3 2013 0.28 6 #> 8 -163. 53.7 2013 1.64 6 #> 9 -163. 60.3 2013 2.06 6 #> 10 -163. 67.0 2013 2.09 6 #> # ... with 602 more rows #>