This definitely looks like a bug and should really be reported. Denes' diagnosis is right on.
I get the bug here: > z <- lm(rnorm(10)~I(1:10)) > > predict(z, int="conf", scale=1) Error in predict.lm(z, int = "conf", scale = 1) : object 'w' not found And also here: > z <- lm(rnorm(10)~I(1:10)) > > predict(z, se.fit=T, scale=1) Error in predict.lm(z, se.fit = T, scale = 1) : object 'w' not found ** platform x86_64-w64-mingw32 arch x86_64 os mingw32 system x86_64, mingw32 status major 3 minor 0.2 year 2013 month 09 day 25 svn rev 63987 language R version.string R version 3.0.2 (2013-09-25) nickname Frisbee Sailing ** -----Original Message----- From: peter dalgaard [mailto:pda...@gmail.com] Sent: Saturday, November 16, 2013 4:36 AM To: Charles Berry Cc: r-help Subject: Re: [R] Bug in predict.lm? On 16 Nov 2013, at 03:06 , Charles Berry <ccbe...@ucsd.edu> wrote: > Rolf Turner <r.turner <at> auckland.ac.nz> writes: > >> >> >> I *do* see the same phenomenon that Bert describes and the code of >> predict.lm() >> *does* appear to contain a bug. There is a line: >> > [snip] > >> >> The operative difference between my set-up and Chuck's is that I am >> using version 3.0.2 Patched. So I am very puzzled as to why Chuck >> does *not* get an error thrown! >> > > [rest deleted] > > The answer is that I made a rookie error. > > I ran > > example(predict.lm) > > before trying Bert's ECM. > > And then I did not bother to see what example(predict.lm) left lying > around in R_GlobalEnv ... > > As you can probably guess, there was an object called 'w'. > > So predict.lm finds it and is.null(w) is FALSE. > > Mea culpa! Hmm, maybe, but this is the sort of thing that code analysis tries to catch (as in "no visible binding for global variable 'w'"). Apparently, the code checker is not smart enough to detect cases where a local variable is _sometimes_ not defined. -- Peter Dalgaard, Professor, Center for Statistics, Copenhagen Business School Solbjerg Plads 3, 2000 Frederiksberg, Denmark Phone: (+45)38153501 Email: pd....@cbs.dk Priv: pda...@gmail.com ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.