Re: [R] comments in scan

2006-11-27 Thread Duncan Murdoch
On 11/27/2006 9:23 PM, Jarrett Byrnes wrote:
> Right, but what if it is not the first line?  

If it's not the first line, then you should follow the instructions that 
start on the 4th line of my reply.

Duncan Murdoch


For example
> 
> #data block 1
> 34,54,23
> 23,53,12
> 35,23,23
> #data block 2
> 64,24,13
> 354,24,12
> 324,13,3
> 
> On Nov 27, 2006, at 4:39 PM, Duncan Murdoch wrote:
> 
>> On 11/27/2006 7:25 PM, Jarrett Byrnes wrote:
>>> I had a question about scan in R.  For better code readability, I   
>>> would like to have lines in the block of data to be scanned that  
>>> are  commented - not just lines that have a comment at the end.   
>>> For example
>>> #age, weight, height
>>> 33,128,65
>>> 34,56,155
>>> instead of having to do something like
>>> 33,128,65 #age, weight, height
>>> 34,56,155
>>> Is this at all possible?
>> If it's on the first line, it's easy:  just use skip=1 to skip the  
>> first line.
>>
>> The general case
>>
>> #age, weight, height
>> 33,128,65
>> # and now for something completely different
>> 34,56,155
>>
>> probably needs something like this:
>>
>>  scan("foo", what=list(0,0,0), comment.char="#", sep=",",  
>> multi.line=T)
>>
>> i.e. you need to tell it how many objects are in a record, and  
>> allow records to span multiple lines.  Watch out for typos in the  
>> file that put different numbers of entries on each line, because  
>> scan() won't complain about it.
>>
>> Duncan Murdoch

__
R-help@stat.math.ethz.ch 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.


Re: [R] comments in scan

2006-11-27 Thread Jarrett Byrnes
Right, but what if it is not the first line?  For example

#data block 1
34,54,23
23,53,12
35,23,23
#data block 2
64,24,13
354,24,12
324,13,3

On Nov 27, 2006, at 4:39 PM, Duncan Murdoch wrote:

> On 11/27/2006 7:25 PM, Jarrett Byrnes wrote:
>> I had a question about scan in R.  For better code readability, I   
>> would like to have lines in the block of data to be scanned that  
>> are  commented - not just lines that have a comment at the end.   
>> For example
>> #age, weight, height
>> 33,128,65
>> 34,56,155
>> instead of having to do something like
>> 33,128,65 #age, weight, height
>> 34,56,155
>> Is this at all possible?
>
> If it's on the first line, it's easy:  just use skip=1 to skip the  
> first line.
>
> The general case
>
> #age, weight, height
> 33,128,65
> # and now for something completely different
> 34,56,155
>
> probably needs something like this:
>
>  scan("foo", what=list(0,0,0), comment.char="#", sep=",",  
> multi.line=T)
>
> i.e. you need to tell it how many objects are in a record, and  
> allow records to span multiple lines.  Watch out for typos in the  
> file that put different numbers of entries on each line, because  
> scan() won't complain about it.
>
> Duncan Murdoch

__
R-help@stat.math.ethz.ch 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.


Re: [R] comments in scan

2006-11-27 Thread Simon Blomberg
You may want to set blank.lines.skip=TRUE too.

Simon.

> From ?scan :
> 
> If |comment.char| occurs (except inside a quoted character field), it 
> signals that the rest of the line should be regarded as a comment and be 
> discarded. Lines beginning with a comment character (possibly after 
> white space with the default separator) are treated as blank lines.
> 
> So, set comment.char="#"
> 
> and you should be fine.
> 
> Cheers,
> 
> Simon.
> 
> Jarrett Byrnes wrote:


> I had a question about scan in R.  For better code readability, I  
> would like to have lines in the block of data to be scanned that are  
> commented - not just lines that have a comment at the end.  For example
>
> #age, weight, height
> 33,128,65
> 34,56,155
>
> instead of having to do something like
>
> 33,128,65 #age, weight, height
> 34,56,155
>
>
> Is this at all possible?
>
> __
> R-help@stat.math.ethz.ch 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.
>
>   


-- 
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat.
Centre for Resource and Environmental Studies
The Australian National University
Canberra ACT 0200
Australia
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C

The combination of some data and an aching desire for
an answer does not ensure that a reasonable answer
can be extracted from a given body of data.
- John Tukey.

__
R-help@stat.math.ethz.ch 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.


Re: [R] comments in scan

2006-11-27 Thread Simon Blomberg
 From ?scan :

If |comment.char| occurs (except inside a quoted character field), it 
signals that the rest of the line should be regarded as a comment and be 
discarded. Lines beginning with a comment character (possibly after 
white space with the default separator) are treated as blank lines.

So, set comment.char="#"

and you should be fine.

Cheers,

Simon.

Jarrett Byrnes wrote:
> I had a question about scan in R.  For better code readability, I  
> would like to have lines in the block of data to be scanned that are  
> commented - not just lines that have a comment at the end.  For example
>
> #age, weight, height
> 33,128,65
> 34,56,155
>
> instead of having to do something like
>
> 33,128,65 #age, weight, height
> 34,56,155
>
>
> Is this at all possible?
>
> __
> R-help@stat.math.ethz.ch 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.
>
>   


-- 
Simon Blomberg, B.Sc.(Hons.), Ph.D, M.App.Stat. 
Centre for Resource and Environmental Studies
The Australian National University  
Canberra ACT 0200   
Australia   
T: +61 2 6125 7800 email: Simon.Blomberg_at_anu.edu.au
F: +61 2 6125 0757
CRICOS Provider # 00120C

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer 
can be extracted from a given body of data.
- John Tukey.

__
R-help@stat.math.ethz.ch 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.


Re: [R] comments in scan

2006-11-27 Thread Duncan Murdoch
On 11/27/2006 7:25 PM, Jarrett Byrnes wrote:
> I had a question about scan in R.  For better code readability, I  
> would like to have lines in the block of data to be scanned that are  
> commented - not just lines that have a comment at the end.  For example
> 
> #age, weight, height
> 33,128,65
> 34,56,155
> 
> instead of having to do something like
> 
> 33,128,65 #age, weight, height
> 34,56,155
> 
> 
> Is this at all possible?

If it's on the first line, it's easy:  just use skip=1 to skip the first 
line.

The general case

#age, weight, height
33,128,65
# and now for something completely different
34,56,155

probably needs something like this:

  scan("foo", what=list(0,0,0), comment.char="#", sep=",", multi.line=T)

i.e. you need to tell it how many objects are in a record, and allow 
records to span multiple lines.  Watch out for typos in the file that 
put different numbers of entries on each line, because scan() won't 
complain about it.

Duncan Murdoch

__
R-help@stat.math.ethz.ch 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.