From Gregor.Gorjanc at bfro.uni-lj.si  Fri Jul 25 13:30:11 2008
From: Gregor.Gorjanc at bfro.uni-lj.si (Gorjanc Gregor)
Date: Fri, 25 Jul 2008 13:30:11 +0200
Subject: [Rd] head() for files
Message-ID: <F189E18BBAA8B6479F618B9044CF4E9C686C1337E2@owa.bfro.uni-lj.si>

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



[Rd] head() for files
Gorjanc Gregor