File: getFirstLast.R

package info (click to toggle)
r-cran-bbmisc 1.13.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,256 kB
  • sloc: ansic: 176; sh: 9; makefile: 5
file content (20 lines) | stat: -rw-r--r-- 449 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#' @title Get the first/last element of a list/vector
#'
#' @description
#' Returns the first or last element of a list or vector.
#'
#' @param x [\code{list} | \code{vector}]\cr
#'   The list or vector.
#' @return Selected element. The element name is dropped.
#' @export
getFirst = function(x) {
  assertVector(x, min.len = 1L)
  x[[1L]]
}

#' @rdname getFirst
#' @export
getLast = function(x) {
  assertVector(x, min.len = 1L)
  x[[length(x)]]
}