bug in "all.vars()"

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

bug in "all.vars()"

Daniel Lüdecke
Hello,
I'm not sure if the following is intended, or a bug, but "all.vars()"
returns different values, depending on whether "TRUE" or "T" is used inside
"poly()":

m1 <- lm(Sepal.Length ~ poly(Sepal.Width, 2, raw = TRUE) + Petal.Length,
data = iris)
m2 <- lm(Sepal.Length ~ poly(Sepal.Width, 2, raw = T) + Petal.Length, data =
iris)

all.vars(formula(m1))
#> [1] "Sepal.Length" "Sepal.Width"  "Petal.Length"
all.vars(formula(m2))
#> [1] "Sepal.Length" "Sepal.Width"  "T"            "Petal.Length"

I know that "T" is no reserved word, but rather a global variable.
Nonetheless, I just wanted to be clear if there is a bug, or everything
works as intended.

Best
Daniel


--

_____________________________________________________________________

Universitätsklinikum Hamburg-Eppendorf; Körperschaft des öffentlichen Rechts; Gerichtsstand: Hamburg | www.uke.de
Vorstandsmitglieder: Prof. Dr. Burkhard Göke (Vorsitzender), Joachim Prölß, Prof. Dr. Blanche Schwappach-Pignataro, Marya Verdel
_____________________________________________________________________

SAVE PAPER - THINK BEFORE PRINTING

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: bug in "all.vars()"

Duncan Murdoch-2
On 15/12/2020 7:33 a.m., Daniel Lüdecke wrote:

> Hello,
> I'm not sure if the following is intended, or a bug, but "all.vars()"
> returns different values, depending on whether "TRUE" or "T" is used inside
> "poly()": >
> m1 <- lm(Sepal.Length ~ poly(Sepal.Width, 2, raw = TRUE) + Petal.Length,
> data = iris)
> m2 <- lm(Sepal.Length ~ poly(Sepal.Width, 2, raw = T) + Petal.Length, data =
> iris)
>
> all.vars(formula(m1))
> #> [1] "Sepal.Length" "Sepal.Width"  "Petal.Length"
> all.vars(formula(m2))
> #> [1] "Sepal.Length" "Sepal.Width"  "T"            "Petal.Length"
>
> I know that "T" is no reserved word, but rather a global variable.
> Nonetheless, I just wanted to be clear if there is a bug, or everything
> works as intended.


It looks as though it is working as documented.  formula(m2) gives

Sepal.Length ~ poly(Sepal.Width, 2, raw = T) + Petal.Length

and all.vars says it returns "a character vector containing all the
names which occur in an expression or call."  "T" is a name.

There are good reasons why "R CMD check" warns about using T when you
mean TRUE.

Duncan Murdoch

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel