[R] More info - S-Plus compatability
ripley@stats.ox.ac.uk
ripley at stats.ox.ac.uk
Fri Jan 17 14:06:03 CET 2003
R's and S-PLUS's write.table functions have different arguments with
different defaults: discussed in MASS4, for example. You appear to need
sep = "," (and FLASE appears to be a typo). It would be better to use
col.names=FALSE and omit the skip=1.
Three other comments:
_ is deprecated in both R and S-PLUS, and makes for unreadable code.
Please don't use it, especially not in postings.
\ needs to be escaped in S/R character strings, hence "\\" is the
character \ (and this *is* in the R FAQ!).
_Data in S-PLUS 4.x (including 2000) is a private directory, and users
really should not be writing in it like this. There is a perfectly
good function tempfile() to create temporary files. Why one needs to
write out and read back the data is unclear to me.
I would find it much faster to read the FAQs and a good book than to keep
asking for help, but your mileage may vary. It looks like time would be
better spent learning to do this well rather than learning to replicate
poor S-PLUS code in R.
On Fri, 17 Jan 2003, Neil Shephard wrote:
> Dear all,
>
> Thanks to those of you who have replied, the majority of the
> comments pointed out that the error caused by scan may originate
> from another function, and closer inspection of the output from
> traceback() reveals that it is in fact the read.table function where
> the error is originating from the full output of which I have included
> below.
>
> The error msg I recieve is
>
> Error in scan(file = file, what = what, sep = sep, quote = quote, dec
> = dec, :
> line 1 did not have 2 elements
> Execution halted.
>
> traceback()
>
> 8: scan(file=file, what=what, sep = sep, quote = quote, dec = dec,
> nmax = nrows, skip =0, na.strings, quiet = TRUE, fill = fill,
> strip.white = strip.white, nlak.lines.skip = blank.lines.skip,
> multi.line = FLASE, comment.char = comment.char)
> 7: read.table("_data\\TempFile, sep = ",", col.names = c("pair1",
> "pair2"))
> 6:ReadIBD.data("ibd.out")
> 5:RunGH(dat)
> 4:Read.Data(dat, x, HRallele)
> 3:eval.with.vis(expr, envir, enclos)
> 2:eval.with.vis(ei, envir)
> 1:source("TrendTest.Main.SSC")
>
> grep -e 'read.table; *.SSC
>
> indicates that the read.table() function is called in ReadIBD.SSC on
> lines seven and twelve, and that the error is occuring with the
> second read.table() where the file '_Data\\TempFile' is being read
> (see copy of ReadIBD.data.SSC below).
>
> ReadIBD.data_function(file) {
>
> ### Funtion to read the IBD probability data from GENEHUNTER
> ### This data was generated from using "Dump IBD" command in
> GENEHUNTER
> ### File = ibd.out file from genehunter
>
> temp_read.table(file, skip=1, col.names=c("pos","pedid", "pair",
> "prior.c0", "prior.c1", "prior.c2", "post.c0", "post.c1",
> "post.c2"),
> row.names=NULL)
>
> write.table(temp$pair,file="_Data\\TempFile")
> pairTemp_read.table("_Data\\TempFile", sep=",",
> col.names=c("pair1","pair2"))
>
> ibd_cbind.data.frame(temp,pairTemp)
> return(ibd)
> }
>
>
> Whilst not overly familiar with R/S-Plus syntax there are a couple
> of things I've noticed, firstly the second file that is trying to be read
> (where the error occurs) is actually called '_Data\TempFile' instead
> of '_Data\\TempFile'. Secondly the columns do not appear to be
> seperated by "," as indicated in the read.table() statement, the
> numbers are encapsulated by "" and are seperated by blank space
> as shown in the sample below.
>
> "x"
> "1" "1,2"
> "2" "1,3"
> "3" "1,4"
> ..
> ..
>
> I now have the problem of trying to workout why the "x" occurs on
> the first row (as this is clearly where the error is occuring as the
> Error statement indicates "line 1 did not have 2 elements").
>
> grep -e '_Data' *.SSC
>
> reveals that the _Data\\TempFile is created on the previous line of
> ReadIBD.Data.SSC after having read the file 'ibd.out'. So I'm not
> sure why the first line is being created with "x" on the first line as
> the 'ibd.out' file is the correct format (I checked this visually). It
> may be a problem with the way in which the 'ibd.out' file is being
> read by R that is causing this, but I'm not sure.
>
> Can anyone see any potential problems with the read.table() and
> write.table() functions in the above script file???
>
> Thanks again to all who offered help, and in anticipation of
> responses to this msg,
>
> Regards
>
> Neil
>
> Neil Shephard
> Genetics Statistician
> ARC Epidemiology Unit, University of Manchester
> neil.shephard at man.ac.uk
> neil.shephard at mindless.com
>
> "Contrariwise, if it was so, it might be; and if it
> were so it would be; but as it isn't, it ain't. That's
> logic" - Tweedledee (Alice Through the Looking Glass)
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> http://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
--
Brian D. Ripley, ripley at stats.ox.ac.uk
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
More information about the R-help
mailing list