[Rd] Patch to allow negative argument in head() and tail()

Vincent Goulet vincent.goulet at act.ulaval.ca
Mon Jul 17 21:03:34 CEST 2006


Dear developeRs (and other abuseRs ;-),

I would like to contribute a patch against functions head() and tail() of 
package utils to allow for a negative 'n' argument. This allows to extract 
all but the first/last 'n' elements/rows/lines of an object, similar to 
the "drop" operator of APL. [1]

I put the patched head.R and head.Rd files, along with diff files in

	http://vgoulet.act.ulaval.ca/pub/R/

The differences were obtained against today's version of r-devel (more 
specifically revision 30277 of head.R and revision 30915 of head.Rd).

Some comments:

- The current version of head() and tail() will accept a vector of length > 1 
for argument 'n' but will silently use the smallest value. This became 
awkward to reproduce in my versions and did not seem interesting anyway. 
Instead, I added an error message if length(n)  > 1.

- I used the word "scalar" in the aforementioned error message to mean a 
vector of length 1. Perhaps is this not the correct R terminology?

- I added a 'addrownums = TRUE' argument to head() used when n < 0, similar to 
tail() with n > 0. This required to write separate methods for 
classes 'data.frame' and 'matrix'.

- The 'function' methods are not modified.

- In the man page, the 'function' method was not documented in the usage 
section. Done now.

- I don't think the patch would break any existing code, except code using the 
(undocumented) "feature" mentioned in my first remark, above.

I hope you will find my (albeit small) contribution useful.

Best regards,

-----
[1] See previous messages to r-devel by myself 
<https://stat.ethz.ch/pipermail/r-devel/2005-April/032881.html>
and Bill Venables 
<https://stat.ethz.ch/pipermail/r-devel/2005-May/033081.html>

-- 
  Vincent Goulet, Associate Professor
  École d'actuariat
  Université Laval, Québec 
  Vincent.Goulet at act.ulaval.ca   http://vgoulet.act.ulaval.ca



More information about the R-devel mailing list