[Rd] head() for files

Gorjanc Gregor Gregor.Gorjanc at bfro.uni-lj.si
Fri Jul 25 13:30:11 CEST 2008


Hi!

I was thinking about using the head and tail functions also for files i.e.
show me the first/last few lines of a file. For example:

zz <- file("ex.data", "w")  # open an output file connection
cat("TITLE extra line", "2 3 5 7", "", "11 13 17", file = zz, sep = "\n")
cat("One more line\n", file = zz)
close(zz)
readLines("ex.data")

head.character <- function(x, n=6, ...) readLines(con=x, n=n, ...)

head.character("ex.data")

As can be seen, this is essentially a wrapper for readLines, but a handy one.
Of course, S3 "linking" is needed, perhaps also for class "connection".

I am not prefectly satisfied with it as I would like to see printout line by line.
Any ideas?

--
Lep pozdrav / With regards,
    Gregor Gorjanc
----------------------------------------------------------------------
University of Ljubljana     PhD student
Biotechnical Faculty        www: http://gregor.gorjanc.googlepages.com
Zootechnical Department     blog: http://ggorjan.blogspot.com
Groblje 3                   mail: gregor.gorjanc <at> bfro.uni-lj.si
SI-1230 Domzale             fax: +386 (0)1 72 17 888
Slovenia, Europe            tel: +386 (0)1 72 17 861



More information about the R-devel mailing list