Re: [R] as.character and a formula

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Wed 17 Aug 2005 - 05:18:04 EST

I guess the problem is that Gavin is unaware of what [[]] does for a call. It is still a call and so you want to use deparse() and not as.character():

> deparse(fmla[[3]])

[1] "spp1 + spp2 + spp3 + spp5"

Watch out for the line length limit on deparse() if you do this in programs.

On Tue, 16 Aug 2005, Uwe Ligges wrote:

> Gavin Simpson wrote:
>
>> Dear list,
>>
>> given this formula:
>>
>>
>>> fmla <- formula(y1 ~ spp1 + spp2 + spp3 + spp5)
>>> fmla[[3]]
>>
>> spp1 + spp2 + spp3 + spp5
>>
>> is this the intended behaviour of as.character:
>>

>>
>>> as.character(fmla[[3]])
>>
>> [1] "+" "spp1 + spp2 + spp3" "spp5"
>>
>> ? Where does the extra "+" come from?

>
> Which *extra* "+"?
>
> This expression is the same as
>
> "+"(spp1 + spp2 + spp3, spp5)
>
> hence "+" with arguments "spp1 + spp2 + spp3" and "spp5"
>
> Same below.
>
> Uwe Ligges
>
>
>>
>>> as.character(fmla)
>>
>> [1] "~" "y1"
>> [3] "spp1 + spp2 + spp3 + spp5"
>>
>> Thanks in advance,
>>
>> Gav
>
> ______________________________________________
> 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
>

-- 
Brian D. Ripley,                  ripley@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

______________________________________________
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
Received on Wed Aug 17 05:31:04 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:24:16 EST