[Rd] Behaviour of mle and environments or calling mle inside a function

From: Iago Mosqueira <iago.mosqueira_at_gmail.com>
Date: Tue, 26 Jun 2007 18:06:38 +0200


Dear all,

I would appreciate some help understanding the following behaviour when stats4::mle is called inside a function. mle seems to look for its arguments in R_GlobalEnv and not the environment from which it is called.

library(stats4)

lkhd <- function(alpha=1, beta=0.1, sigma=0.1)

object <- list(lkhd=lkhd, rec=1:10, ssb=1:10)

foo <- function(x)
{

	rec <- x$rec
	ssb <- x$ssb

	mle(x$lkhd)

}

foo(object)

This fails with

Error in log(rec) : object "rec" not found

rec <- object$rec
ssb <- object$ssb

foo(object)

and this works.

Using R version 2.5.0 (2007-04-23), on Linux (Ubuntu) 2.6.17

Many thanks,

Iago Mosqueira



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Tue 26 Jun 2007 - 16:32:23 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 26 Jun 2007 - 18:35:45 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.