```
head(letters)
head(letters, n = -6L)
head(freeny.x, n = 10L)
head(freeny.y)
head(iris3)
head(iris3, c(6L, 2L))
head(iris3, c(6L, -1L, 2L))
tail(letters)
tail(letters, n = -6L)
tail(freeny.x)
## the bottom-right "corner" :
tail(freeny.x, n = c(4, 2))
tail(freeny.y)
tail(iris3)
tail(iris3, c(6L, 2L))
tail(iris3, c(6L, -1L, 2L))
## iris with dimnames stripped
a3d <- iris3 ; dimnames(a3d) <- NULL
tail(a3d, c(6, -1, 2)) # keepnums = TRUE is default here!
tail(a3d, c(6, -1, 2), keepnums = FALSE)
## data frame w/ a (non-standard) attribute:
treeS <- structure(trees, foo = "bar")
(n <- nrow(treeS))
stopifnot(exprs = { # attribute is kept
identical(htS <- head(treeS), treeS[1:6, ])
identical(attr(htS, "foo") , "bar")
identical(tlS <- tail(treeS), treeS[(n-5):n, ])
## BUT if I use "useAttrib(.)", this is *not* ok, when n is of length 2:
## --- because [i,j]-indexing of data frames *also* drops "other" attributes ..
identical(tail(treeS, 3:2), treeS[(n-2):n, 2:3] )
})
tail(library) # last lines of function
head(stats::ftable(Titanic))
## 1d-array (with named dim) :
a1 <- array(1:7, 7); names(dim(a1)) <- "O2"
stopifnot(exprs = {
identical( tail(a1, 10), a1)
identical( head(a1, 10), a1)
identical( head(a1, 1), a1 [1 , drop=FALSE] ) # was a1[1] in R <= 3.6.x
identical( tail(a1, 2), a1[6:7])
identical( tail(a1, 1), a1 [7 , drop=FALSE] ) # was a1[7] in R <= 3.6.x
})
```

Run the code above in your browser using DataLab