[Rd] Add first() and last() to utils?

Michael Lawrence lawrence.michael at gene.com
Fri May 1 23:30:21 CEST 2015

I would argue that it should be:

first <- function(x, ...) head(x, n=1L, ...)

So it's simpler and we don't have people using first() and head()
interchangeably for non-default 'n'. first() should mean "the" first. That
also avoids forcing 'n' to be in the formals of every generic+method. Of
course, there is still the problem of conflicting semantics with existing
functions. For example, GenomicAlignments has first() meaning the first
sequence alignment for all pairs, whereas with these semantics it would be
the first alignment of the dataset, if that makes any sense. Of course, we
could rename those to something, but this might not be the only case...

On Tue, Apr 28, 2015 at 12:11 PM, Gregory Warnes <greg at warnes.net> wrote:

> Hi all,
> I've been using first() and last() for some time instead of x[1] and
> x[length(x)] for vectors, and I gradually added methods for lists,
> matrices, and data.frames.
> In preparing the next release of the 'gdata' package (2.16.1) I settled on
> these definitions, which harness the existing methods for head() and
> tail():
> # Simply call 'first' or 'last' with a different default value for 'n'.
> first <- function(x, n=1, ...) head(x, n=n, ...)
> last  <- function(x, n=1, ...) tail(x, n=n, ...)
> This works nicely, but Brian noted that packages 'data.table' and 'xts'
> also provide functions/S3 methods for head() and/or tail().
> Would it make sense to add these definitions to package 'utils' to make
> them generally available?
> -Greg
> --
> "Whereas true religion and good morals are the only solid foundations of
> public liberty and happiness . . . it is hereby earnestly recommended to
> the several States to take the most effectual measures for the
> encouragement thereof." Continental Congress, 1778
>         [[alternative HTML version deleted]]
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

	[[alternative HTML version deleted]]

More information about the R-devel mailing list