Message-ID: <x2slx9r7jn.fsf@turmalin.kubism.ku.dk>
Date: 2005-08-16T19:44:12Z
From: Peter Dalgaard
Subject: as.character and a formula
In-Reply-To: <1124215476.8689.120.camel@gsimpson.geog.ucl.ac.uk>
Gavin Simpson <gavin.simpson at ucl.ac.uk> writes:
> 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"
Yes.
> ? Where does the extra "+" come from?
What extra "+" ? There are three of them in fmla[[3]] and three in
as.character(....).
as.character of an object of mode call is obtained by converting it to
a list and deparsing each term (modulo some details regarding
backquotes). This is somewhat peculiar, but quite a bit of legacy code
is depending on it. Things like testing for as.character(e)[1] == "~"
--
O__ ---- Peter Dalgaard ??ster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907