Bug in loglin with variable called "c" (PR#198)

ripley@stats.ox.ac.uk ripley@stats.ox.ac.uk
Sun, 23 May 1999 08:59:02 +0200 (MET DST)


Summary:

loglin will fail if there is a global variable called c. I have
fixed this for 0.64.2 and 0.65.

On Sat, 22 May 1999, Cor en Aylin wrote:

> Dear Brian,
> 
> Using the mass library for R (the most recent port dated 16 may 1999) I

Could you give version numbers in such reports please: at the moment there
is an official version (5.3pl037) of MASS for R, plus a pre-release of MASS
for V&R3, and you seem to be using the latter.  That is _not_ the most
recent port:  it is a different major version (6.1 not 5.3) and please
don't use it unless you like testing pre-release software. BTW, the name is
MASS, not mass or Mass: it is an acronym.

> have encountered a minor problem you  might want to be informed about :
> 
> If used the following command:
>   mydata.loglm <- loglm(n~ s+c+m, mydata)
> 
> I got an the following error :  Error in get(x, envir, mode, inherits) :
> variable "FUN" was not found
> 
> traceback()
> [1] "get(as.character(f), mode = \"function\")"
> [2] "match.fun(FUN)"
> [3] "lapply(y, c, x[i])"
> [4] "subsets(margin[[k]])"
> [5] "loglin(data, margins, start = start, fit = fitted, param = param, "
> 
> [6] "    eps = eps, iter = iter, print = print)"
> [7] "loglm1.default(formula, data, ..., start = st)"
> [8] "loglm1.data.frame(formula, data, ...)"
> [9] "loglm(n ~ s + m + c, mydata )"
> 
> Trying to see where the problem sits within loglin I saw that (line 3 of
> traceback) variable "c" is used in lapply, and since my data-variable
> also is called "c" mine was used instead (wrongly). I understood the
> message and I think that I better not use often uses variable-names
> (a..z) as names for my data-vars.

The problem is not in MASS: it is occurring in the R version of loglin.

To reproduce this I have to have a global variable c, not a column c in
the dataframe. So that is the workaround: make your variables columns in 
mydata. Here is a example:

library(MASS)
data(quine)
c <- quine$Eth
loglm(Days ~ .^2, quine)

To fix this in R, the line in loglin needs to be lapply(y, "c", x[i]).

Kurt: do you want explicitly to get c() from package:base here, to be
safer, or would that be too restrictive?

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._