Skip to content

Commit e80a21b

Browse files
Clarify behavior of first() and last() (#7056)
* clarify first() vs x[1] * also updated docs for last * mention similar behaviour of head(,1) with integer(0) * head() and tail() preserve attributes * Final
1 parent 2642b84 commit e80a21b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

man/last.Rd

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ of \code{xts::first} is deployed. }
1818
\item{\dots}{ Not applicable for \code{data.table} first/last. Any arguments here
1919
are passed through to \code{xts}'s first/last. }
2020
}
21+
\details{
22+
Note: For zero-length vectors, \code{first(x)} and \code{last(x)} mimic \code{head(x, 1)} and \code{tail(x, 1)} by returning an empty vector instead of \code{NA}. However, unlike \code{head()}/\code{tail()} and base R subsetting (e.g., \code{x[1]}), they do not preserve attributes like names.
23+
}
2124
\value{
2225
If no other arguments are supplied it depends on the type of \code{x}. The first/last item
2326
of a vector or list. The first/last row of a \code{data.frame} or \code{data.table}.

0 commit comments

Comments
 (0)