On the subject of connections, you can do Unix-style preprocessing of a file
using a pipe in Splus6. For instance this example strips out double-quotes
from the .txt file before read.table gets to it.
con <- pipe("sed -e \"s/\\\\\"//g\" dredge.txt")
dredge <- read.table(con,header=T,sep=",")
It works on Windows too if you have the cygwin utilities installed.
For Stephen Tallon's example, one can select particular ranges of a file
using a pipe command, e.g.
sed -n '1001,1500p' myfile
or
tail +1001 myfile | head -500
selects lines 1001 to 1500.
(If the first example looks a bit obscure, it's because the backslashes need
a lot of escaping to survive the journey to the shell command. Simpler
example is
con <- pipe("sed -e \"s/ABC/XYZ/g\" dredge.txt")
dredge <- read.table(con,header=T,sep=",")
which changes all ABC's to XYZ.)
Nick Ellis
CSIRO Marine Research mailto:Nick.Ellis@csiro.au
PO Box 120 ph +61 (07) 3826 7260
Cleveland QLD 4163 fax +61 (07) 3826 7222
Australia http://www.marine.csiro.au
|