Each element returned by i_window(obj)
consists of n
consecutive
elements from the underlying obj
, with the window advancing
forward by one element each iteration.
Arguments
- obj
An iterable.
- n
The width of the window to apply
- tail
If a value is given, tails will be included at the beginning and end of iteration, filled with the given value.
- ...
passed along to
iteror(object, ...)
Examples
#' @examples
it <- i_window(iteror(letters[1:4]), 2)
nextOr(it, NA) # list("a", "b")
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
nextOr(it, NA) # list("b", "c")
#> [[1]]
#> [1] "b"
#>
#> [[2]]
#> [1] "c"
#>
nextOr(it, NA) # list("c", "d")
#> [[1]]
#> [1] "c"
#>
#> [[2]]
#> [1] "d"
#>
it2 <- i_window(icount(5), 2)
nextOr(it2, NA) # list(1, 2)
#> [[1]]
#> [1] 1
#>
#> [[2]]
#> [1] 2
#>
nextOr(it2, NA) # list(2, 3)
#> [[1]]
#> [1] 2
#>
#> [[2]]
#> [1] 3
#>
nextOr(it2, NA) # list(3, 4)
#> [[1]]
#> [1] 3
#>
#> [[2]]
#> [1] 4
#>
nextOr(it2, NA) # list(4, 5)
#> [[1]]
#> [1] 4
#>
#> [[2]]
#> [1] 5
#>
it <- i_window(letters[1:4], 2)
nextOr(it, NA) # list("a", "b")
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
nextOr(it, NA) # list("b", "c")
#> [[1]]
#> [1] "b"
#>
#> [[2]]
#> [1] "c"
#>
nextOr(it, NA) # list("c", "d")
#> [[1]]
#> [1] "c"
#>
#> [[2]]
#> [1] "d"
#>
it <- i_window(letters[1:4], 3)
nextOr(it) # list("a", "b", "c")
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
#> [[3]]
#> [1] "c"
#>
nextOr(it) # list("b", "c", "d")
#> [[1]]
#> [1] "b"
#>
#> [[2]]
#> [1] "c"
#>
#> [[3]]
#> [1] "d"
#>
it <- i_window(letters[1:4], 3, tail=" ")
nextOr(it) # list(" ", " ", "a")
#> [[1]]
#> [1] " "
#>
#> [[2]]
#> [1] " "
#>
#> [[3]]
#> [1] "a"
#>
nextOr(it) # list(" ", "a", "b")
#> [[1]]
#> [1] " "
#>
#> [[2]]
#> [1] "a"
#>
#> [[3]]
#> [1] "b"
#>
nextOr(it) # list("a", "b", "c")
#> [[1]]
#> [1] "a"
#>
#> [[2]]
#> [1] "b"
#>
#> [[3]]
#> [1] "c"
#>
nextOr(it) # list("b", "c", "d")
#> [[1]]
#> [1] "b"
#>
#> [[2]]
#> [1] "c"
#>
#> [[3]]
#> [1] "d"
#>
nextOr(it) # list("c", "d", " ")
#> [[1]]
#> [1] "c"
#>
#> [[2]]
#> [1] "d"
#>
#> [[3]]
#> [1] " "
#>
nextOr(it) # list("d", " ", " ")
#> [[1]]
#> [1] "d"
#>
#> [[2]]
#> [1] " "
#>
#> [[3]]
#> [1] " "
#>