From nali at umn.edu  Thu Apr 14 19:54:34 2005
From: nali at umn.edu (Na Li)
Date: Thu Apr 14 19:58:12 2005
Subject: [Rd] documentation for 'open': some clarification?
Message-ID: <xky8blp7l1.fsf@bass.local>


I'm been doing more and more of file text parsing inside R instead of
coping with Perl.  For that, I need open a file and read it line-by-line.
I found the documentation for 'open' isn't very clear.

Right now it has

,----[ *help(R)[open]* ]
|  'open' opens a connection.  In general functions using connections
|  will open them if they are not open, but then close them again, so
|  to leave a connection open call 'open' explicitly.
`----

It seems that one has to call 'open' to open a live connection that can be
parsed line by line (using readLines() or scan() to read).  But open()
cannot be directly applied to a file name.

In fact, one only needs supply the 'open' argument in file() with
something other than the empty string,

,----
| > con <- file ("S200.dat")
| > isOpen (con)
| [1] FALSE
| > con <- file ("S200.dat", open = "r")
| > isOpen (con)
| [1] TRUE
`----

It is not clear to me how 'open()' is supposed to be used.  It took me a
while to figure this out and I thought it might be worthwhile to add one
sentence or two to make it more clear in the doc.

Cheers,

Michael

-- 
Na (Michael) Li, Ph.D.               
Division of Biostatistics          A443 Mayo Building, MMC 303   
School of Public Health            420 Delaware St SE            
University of Minnesota            Minneapolis, MN 55455         
Phone: (612) 626-4765              Email: nali@umn.edu                  
Fax:   (612) 626-0660              http://www.biostat.umn.edu/~nali

GPG Public Key: 
http://www.umn.edu/lookup?SET_INSTITUTION=UMNTC&UID=nali&show_pgp=1


[Rd] documentation for 'open': some clarification?
Na Li