From ggrothendieck at gmail.com  Fri Oct 27 13:21:23 2006
From: ggrothendieck at gmail.com (Gabor Grothendieck)
Date: Fri, 27 Oct 2006 07:21:23 -0400
Subject: [Rd] all.names() and all.vars(): sorting order of functions'
	return vector
In-Reply-To: <E4A9111DA23BA048B9A46686BF727CF461BDD7@DEFRAXMB01.corp.amvescap.net>
References: <E4A9111DA23BA048B9A46686BF727CF461BDD7@DEFRAXMB01.corp.amvescap.net>
Message-ID: <971536df0610270421s5c28b228j3041935a4df8bfd1@mail.gmail.com>

Rewrite

   expr2 <- expression(x3 <-  0.5 * x1 - 0.7 * x2)

like this:

   expression(`<-`(x3, `-`(`*`(0.5, x1), `*`(0.7, x2))))

and it becomes clear.

On 10/27/06, Pfaff, Bernhard Dr. <Bernhard_Pfaff at fra.invesco.com> wrote:
> Dear list-subscriber,
>
> in the process of writing a general code snippet to extract coefficients
> in an expression (in the example below: 0.5 and -0.7), I stumbled over
> the following peculiar (at least peculiar to me:-) ) sorting behaviour
> of the function all.names():
>
> > expr1 <- expression(x3 = 0.5 * x1 - 0.7 * x2)
> > all.names(expr1)
> [1] "-"  "*"  "x1" "*"  "x2"
> > all.vars(expr1)
> [1] "x1" "x2"
> > expr2 <- expression(x3 <-  0.5 * x1 - 0.7 * x2)
> > all.names(expr2)
> [1] "<-" "x3" "-"  "*"  "x1" "*"  "x2"
> > all.vars(expr2)
> [1] "x3" "x1" "x2"
> > expr3 <- expression(x3 ~  0.5 * x1 - 0.7 * x2)
> > all.names(expr3)
> [1] "~"  "x3" "-"  "*"  "x1" "*"  "x2"
> > all.vars(expr3)
> [1] "x3" "x1" "x2"
> >
>
> For all.names(expr2) and all.names(expr3) I would expect something like:
>
> [1] "x3" "<-" "*" "x1" "-" "*" "x2"
>
> [1] "x3" "~" "*" "x1" "-" "*" "x2"
>
> To which kind of rule is the sorting order in the returned character
> vector produced? Any help or pointers is much appreciated.
>
> Best,
> Bernhard
>
>
> > sessionInfo()
> R version 2.5.0 Under development (unstable) (2006-10-10 r39600)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=German_Germany.1252;LC_CTYPE=German_Germany.1252;LC_MONETARY=
> German_Germany.1252;LC_NUMERIC=C;LC_TIME=German_Germany.1252
>
> attached base packages:
> [1] "methods"   "stats"     "graphics"  "grDevices" "datasets"  "utils"
>
> [7] "base"
>
> other attached packages:
>    nlme fortunes
> "3.1-77"  "1.3-2"
> >
> *****************************************************************
> Confidentiality Note: The information contained in this mess...{{dropped}}
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>




[Rd] all.names() and all.vars(): sorting order of functions' return vector
Gabor Grothendieck