Sorry, I misunderstood what I was doing and misspoke. I don't think there's a bug. I had called COMMAND w/in read.delim.

Thanks for all of your help and sorry for the misinformation.

Sincerely,

Mike

-----------------------------------------------------
Department of Ecology & Evolutionary Biology
569 Dabney Hall
University of Tennessee
Knoxville, TN 37996-1610

phone:(865) 974-6453
fax:  (865) 974-6042

web: http://eeb.bio.utk.edu/gilchrist.asp
-----------------------------------------------------


On Thu, 18 Sep 2008, Henrik Bengtsson wrote:

On Thu, Sep 18, 2008 at 1:39 PM, Michael A. Gilchrist <[EMAIL PROTECTED]> wrote:
Wow, that's elegant and simple.  It's also faster than my approach.

NB, you don't need to use close(), read.delim() closes the pipe when its
done reading.

If read.delim() close the connection in this case, it's a bug.  It
should only close the connection if it opens it.

/Henrik


Thank you all for your suggestions, they really helped me with this problem
and understand R just a bit better.

Sincerely,

Mike
-----------------------------------------------------
Department of Ecology & Evolutionary Biology
569 Dabney Hall
University of Tennessee
Knoxville, TN 37996-1610

phone:(865) 974-6453
fax:  (865) 974-6042

web: http://eeb.bio.utk.edu/gilchrist.asp
-----------------------------------------------------


On Fri, 12 Sep 2008, Prof Brian Ripley wrote:

Why not use

con <- pipe(COMMAND)
foo <- read.delim(con, colClasses="numeric")
close(con)

?  See the 'R Data Input/Output Manual'.

On Fri, 12 Sep 2008, Michael A. Gilchrist wrote:

Hello,

I am currently using R to run an external program and then read the
results the external program sends to the stdout which are tsv data.

When R reads the results in it converts it to to a list of strings which
I then have to maniuplate with a whole slew of commands (which, figuring out
how to do was a reall challenge for a newbie like myself)--see below.

Here's the code I'm using.  COMMAND runs the external program.

  rawInput= system(COMMAND,intern=TRUE);##read in tsv values
  rawInput = strsplit(rawInput, split="\t");##split elements w/in the
list
                                             ##of character strings by
"\t"
  rawInput = unlist(rawInput); ##unlist, making it one long vector
  mode(rawInput)="double"; ##convert from strings to double
  finalInput = data.frame(t(matrix(rawInput, nrow=6))); ##convert

Because I will be doing this 100,000 of times as part of an optimization
problem, I am interested in learning a more efficient way of doing this
conversion.

Any suggestions would be appreciated.


Thanks in advance.

Mike


-----------------------------------------------------
Department of Ecology & Evolutionary Biology
569 Dabney Hall
University of Tennessee
Knoxville, TN 37996-1610

phone:(865) 974-6453
fax:  (865) 974-6042

web: http://eeb.bio.utk.edu/gilchrist.asp


--
Brian D. Ripley,                  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to