Strange behavior of varComp - difference between R-3.3.3 and R-3.4.2

We define two functions f1and f2that must return the same thing:

# load a dataframe
library(nlme)
data(Oxide)

# run varComp
library(varComp)
varComp(Thickness~Source, Oxide, ~Lot/Wafer) # this works

f1 <- function(dat){
  data <- dat
  varComp(Thickness~Source, data, ~Lot/Wafer)
}

f2 <- function(dat){
  varComp(Thickness~Source, dat, ~Lot/Wafer)
}

R-3.3.3

> f1(Oxide)
Variance component model fit 

Call:
varComp(fixed = Thickness ~ Source, data = data, random = ~Lot/Wafer)


Fixed effect estimates: 
(Intercept)     Source2 
 1995.11111    10.08333 

Variance component estimates: 
      Lot Lot:Wafer     error 
119.89249  35.86574  12.56944 

Number of observations: 72
> f2(Oxide) # error
Error in is.data.frame(data) : object 'dat' not found

How is this error possible when it works f1(Oxide)?

R-3.4.2

> f1(Oxide) # error
Error in eval(predvars, data, env) : object 'Lot' not found
Called from: eval(predvars, data, env)
Browse[1]> f2(Oxide) # other error
Error during wrapup: object 'Lot' not found

Why are there two different errors? And why is the difference compared to R-3.3.3? Any guess?

There varCompis a programming error in, and I would like to understand, because I have a script that works in R-3.3.3, but not in R-3.4.2.

Edit

Now I get different error messages with R-3.4.2:

> f1(Oxide)
Error in as.data.frame.default(data, optional = TRUE) : 
  cannot coerce class ""function"" to a data.frame
> f2(Oxide)
Error in is.data.frame(data) : object 'dat' not found

This works if assigned datnot locally:

> f3 <- function(dat){
+   dat <<- dat
+   varComp(Thickness~Source, dat, ~Lot/Wafer)
+ }
> f3(Oxide)
Variance component model fit 

Call:
varComp(fixed = Thickness ~ Source, data = dat, random = ~Lot/Wafer)
......
+4
source share

Source: https://habr.com/ru/post/1686757/


All Articles