/
head-tail.R
63 lines (49 loc) · 1.29 KB
/
head-tail.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
################################################################################
#' Convert to a tibble of the n first/last elements.
#'
#' @param x A [FDF][FDF-class].
#' @param ... Not used.
#' @param n A single positive integer.
#'
#' @importFrom utils head
#' @export
#' @method head FDF
#'
#' @include filter.R
#'
#' @rdname head
#'
#' @examples
#' test <- FDF(datasets::iris)
#' head(test)
head.FDF <- function(x, n = 6L, ...) {
assert_nodots()
assert_pos(n)
n <- min(n, x$nrow)
as_tibble(filter_int(x, seq_len(n), check = FALSE))
}
################################################################################
#' @exportMethod head
#' @rdname head
setGeneric("head", utils::head)
################################################################################
#' @importFrom utils tail
#' @export
#' @method tail FDF
#'
#' @rdname head
#'
#' @examples
#' test <- FDF(datasets::iris)
#' tail(test)
tail.FDF <- function(x, n = 6L, ...) {
assert_nodots()
assert_pos(n)
n <- min(n, x$nrow)
as_tibble(filter_int(x, x$nrow + seq_len(n) - n, check = FALSE))
}
################################################################################
#' @exportMethod tail
#' @rdname head
setGeneric("tail", utils::tail)
################################################################################