Bug 15275 - terms.formula(y ~ (x + fn(z = NA)) - fn(z = NA),simplify=TRUE) does not simplify
Summary: terms.formula(y ~ (x + fn(z = NA)) - fn(z = NA),simplify=TRUE) does not simplify
Status: NEW
Alias: None
Product: R
Classification: Unclassified
Component: Models (show other bugs)
Version: R 2.15.2
Hardware: x86_64/x64/amd64 (64-bit) Windows 64-bit
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2013-04-15 05:00 UTC by jouni.vt.helske
Modified: 2013-04-22 14:01 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description jouni.vt.helske 2013-04-15 05:00:59 UTC
When using functions containing arguments with NA values, terms.formula simplify, ie. remove the function from the formula:

#Run after starting with R --vanilla:
> rm(list=ls())
> terms.formula(y ~ (x + fn(z = NA)) - fn(z = NA),simplify=TRUE)
y ~ x + fn(z = NA)
attr(,"variables")
list(y, x, fn(z = NA), fn(z = NA))
attr(,"factors")
           x fn(z = NA)
y          0          0
x          1          0
fn(z = NA) 0          1
fn(z = NA) 0          0
attr(,"term.labels")
[1] "x"          "fn(z = NA)"
attr(,"order")
[1] 1 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>

With any other values instead of NA it works like it should:

> terms.formula(y ~ (x + fn(z = 1)) - fn(z = 1),simplify=TRUE)
y ~ x
attr(,"variables")
list(y, x, fn(z = 1))
attr(,"factors")
          x
y         0
x         1
fn(z = 1) 0
attr(,"term.labels")
[1] "x"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>

Also NA_real, NA_logical, and NA_character work as expected:

 terms.formula(y ~ (x + fn(z = NA_real)) - fn(z = NA_real),simplify=TRUE)
y ~ x
attr(,"variables")
list(y, x, fn(z = NA_real))
attr(,"factors")
                x
y               0
x               1
fn(z = NA_real) 0
attr(,"term.labels")
[1] "x"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>

Even more minimalistic version of the same problem:

> terms.formula(y ~ I(NA) - I(NA),simplify=TRUE)
y ~ I(NA)
attr(,"variables")
list(y, I(NA), I(NA))
attr(,"factors")
      I(NA)
y         0
I(NA)     1
I(NA)     0
attr(,"term.labels")
[1] "I(NA)"
attr(,"order")
[1] 1
attr(,"intercept")
[1] 1
attr(,"response")
[1] 1
attr(,".Environment")
<environment: R_GlobalEnv>


> version
               _                            
platform       x86_64-w64-mingw32           
arch           x86_64                       
os             mingw32                      
system         x86_64, mingw32              
status                                      
major          2                            
minor          15.2                         
year           2012                         
month          10                           
day            26                           
svn rev        61015                        
language       R                            
version.string R version 2.15.2 (2012-10-26)
nickname       Trick or Treat