Balzer Susanne
2010-Feb-27 16:24 UTC
[R] scan and skip - without line breaks in the input file
Dear all, I am trying to read in big amounts of data with scan. It's only one variable, numeric values, separated by tabs,.. and it's many of them. So I was thinking that I could use the skip option and read in 100000 values at a time - but skip doesn't work, probably because I don't have line breaks in the txt file. So any value specified for skip makes the scan function jump to the end of the file. Does anyone have a good idea? I would be extremely grateful. Kind regards, Susanne Balzer **************************** Susanne Balzer PhD Student Institute of Marine Research N-5073 Bergen, Norway Phone: +47 55 23 69 45 susanne.balzer at imr.no www.imr.no
David Winsemius
2010-Feb-27 16:38 UTC
[R] scan and skip - without line breaks in the input file
On Feb 27, 2010, at 11:24 AM, Balzer Susanne wrote:> Dear all, > > I am trying to read in big amounts of data with scan. It's only one > variable, numeric values, separated by tabs,.. and it's many of > them. So I was thinking that I could use the skip option and read in > 100000 values at a time - but skip doesn't work, probably because I > don't have line breaks in the txt file. So any value specified for > skip makes the scan function jump to the end of the file.?scan Without a working example it is hard to be sure, but it appears from a rapid look at the help page that nmax is the argument you want. > scan(textConnection('1 2 3 4 5 6 7'), nmax=4) Read 4 items [1] 1 2 3 4 (Ignores line-feeds) > scan(textConnection('1 2 \n 3 4 5 6 7'), nmax=4) Read 4 items [1] 1 2 3 4 -- David.> > Does anyone have a good idea? I would be extremely grateful. > > Kind regards, > > Susanne Balzer > > > > **************************** > Susanne Balzer > PhD Student > Institute of Marine Research > N-5073 Bergen, Norway > Phone: +47 55 23 69 45 > susanne.balzer at imr.no > www.imr.no > > ______________________________________________ > R-help at 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.David Winsemius, MD Heritage Laboratories West Hartford, CT
Gabor Grothendieck
2010-Feb-28 13:30 UTC
[R] scan and skip - without line breaks in the input file
On UNIX/Linux: myData <- scan(pipe("tr '\\t' '\\n' < myfile"), skip = 3) You might have to adjust this depending on your shell. On Windows there is a tr in Duncan Murdoch's Rtools. On Sat, Feb 27, 2010 at 11:24 AM, Balzer Susanne <susanne.balzer at imr.no> wrote:> Dear all, > > I am trying to read in big amounts of data with scan. It's only one variable, numeric values, separated by tabs,.. and it's many of them. So I was thinking that I could use the skip option and read in 100000 values at a time - but skip doesn't work, probably because I don't have line breaks in the txt file. So any value specified for skip makes the scan function jump to the end of the file. > > Does anyone have a good idea? I would be extremely grateful. > > Kind regards, > > Susanne Balzer > > > > **************************** > Susanne Balzer > PhD Student > Institute of Marine Research > N-5073 Bergen, Norway > Phone: +47 55 23 69 45 > susanne.balzer at imr.no > www.imr.no