[R] scan and skip - without line breaks in the input file
Peter Ehlers
ehlers at ucalgary.ca
Sat Feb 27 19:23:19 CET 2010
Talk about asleep at the switch.
My sincere apologies to both Susanne and David for my
stupid message and to group for wasting everyone's time.
Ouch, that headslap hurt.
-Peter
On 2010-02-27 11:05, Peter Ehlers wrote:
> David, Susanne,
>
> There may be a misunderstanding here. As I understand it,
> Susanne wants to be able to read the _second_ (and third, etc)
> 100K values after reading the first 100K, presumably to be
> processed separately for reasons I can't imagine. If that is
> correct, then I have no solution other than inserting
> delimiters before passing off to R.
>
> But Susanne, why do you need to read your data in this
> piece-meal fashion?
>
> -Peter Ehlers
>
> On 2010-02-27 10:46, David Winsemius wrote:
>>
>> On Feb 27, 2010, at 11:47 AM, Balzer Susanne wrote:
>>
>>> Hei David,
>>>
>>> Thanks for your quick response, but unfortunately n and nmax alone
>>> don't do the job. If I want to read items no. 100001 to 200000, the
>>> n=100000 option will work, but skip=100000 (to NOT read the first
>>> 100000 items) won't.
>>>
>>> Or with your example,
>>>
>>> scan(textConnection('1 2 3 4 5 6 7'), skip=3) will never work, while
>>
>> True.
>>>
>>> scan(textConnection('1 2 3 4 \n 5 \n 6 \n 7'), skip=3) will. But I
>>> don't have line breaks in my file.
>>
>> Right. That was what I was trying to help you deal with.
>>
>>>
>>> Is there no way to specify the character for a line break in scan /
>>> read.table / etc.?
>>
>> Why are you fixating on linefeeds when you don't have any?????
>>
>> > closeAllConnections()
>> > tc <- textConnection(paste(1:100, sep=" ", collapse=" "))
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 1 2 3 4 5 6 7 8 9 10
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 11 12 13 14 15 16 17 18 19 20
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 21 22 23 24 25 26 27 28 29 30
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 31 32 33 34 35 36 37 38 39 40
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 41 42 43 44 45 46 47 48 49 50
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 51 52 53 54 55 56 57 58 59 60
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 61 62 63 64 65 66 67 68 69 70
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 71 72 73 74 75 76 77 78 79 80
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 81 82 83 84 85 86 87 88 89 90
>> > scan(tc, nmax=10)
>> Read 10 items
>> [1] 91 92 93 94 95 96 97 98 99 100
>> > scan(tc, nmax=10)
>> Read 0 items
>> numeric(0)
>>
>
--
Peter Ehlers
University of Calgary
More information about the R-help
mailing list