[Rd] Re: more experience with formulas
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Tue, 19 Sep 2000 18:40:43 +0200
>>>>> "WSt" == Werner Stahel <stahel@stat.math.ethz.ch> writes:
[to me privately]
WSt> I do not want to call this a bug, but it bugged me. Please try the
WSt> following:
WSt> tform <- sqrt(RADAI) ~ sqrt(RADAI.e) + TAGE.ej + SPITAL + ARZT + DAS28 +
WSt> SJC + TJC + DGA + HAQ + PGA + PAIN + YEAR.SYM + YEAR.DIA +
WSt> ALTER + IndV + m.NSAIDs + m.Stereoids + DM.Cyclosp + DM.Penic
WSt>
WSt> as.character(tform)
--> length-3 vector "~" "<LHS>" "<RHS>".
However, the end of <RHS> is TRUNCATED!
and that truncation of the third part is a bug in my opinion.
The fact that it returns a vector of the same length as its argument is
very consistent behavior even though it maybe unexpected to the casual R user.
I think you'd want to use format() instead.
There, we can see that format.default really uses deparse(x) when x is such
a language object.
One could argue that the optional "width.cutoff = 60" argument to deparse()
should also be settable from format(), in that case,
since
format(tform) == deparse(tform)
really returns a vector of "3 lines" instead of just one line
which we'd get by the result of
deparse(tfrom, width = 200)
Opinions?
WSt> paste(tform,collapse="")# "y ~ x" becomes "~yx" -- is S compatible
WSt> as.character(tform[[3]])# again length-3 vector "+" "sqr..." "DM.Penic"
WSt>
WSt> as.character.formula <- function(x, ...) paste(deparse(x),collapse="")
WSt> ## now ,
WSt> as.character(tform)
WSt> paste(tform,collapse="")
WSt> ## work, but
WSt> as.character(tform[[3]])
WSt> ## still does not, since it is of mode language, but not of class formula.
WSt> ## It would be better to write as.character.default such that is works for
WSt> ## mode language.
It *does* work; it just returns a vector of character, again
fulfilling the semantic that
when
y <- as.character(x)
then
y[i] == as.character(x[i])
WSt> PS: Thanks for your efforts in developping R.
WSt> Werner Stahel
Martin Maechler <maechler@stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._