Displaying 2 results from an estimated 2 matches for "funfail".
Did you mean:
funmail
2023 May 25
4
environments: functions within functions
...ting the normal mixture models
set.seed(103)
x <- rmixnormal(200, c(0.3, 0.7), c(2, 5), c(1, 1))
data <- bin(x, seq(-1, 8, 0.25))
fit1 <- mixfit(x, ncomp = 2) # raw data
rm(x, data)
###
# simple function
funworks <- function(x) {
print(x)
}
###
# almost identical simple function
funfails <- function(thisx) {
print(thisx)
}
###
funworks(fit1)
funfails(fit1)
#######
The explanation as I understand it...
print called on this object gets passed to print.mixfitEM(), which is:
function (x, digits = getOption("digits"), ...)
{
family <- x$family
mc <...
2023 May 25
1
environments: functions within functions
...<- x$family
> mc <- match.call()
> mc$digits <- digits
> fun.name <- paste0("print", family)
> mc[[1]] <- as.name(fun.name)
> eval(mc, environment())
> }
>
>
> Working through the calls, when eval() is called from within
> funfails(), mc is printnormal(x = thisx, digits = 7)
> and the calling environment does not contain thisx.
Your functions, both funworks and funfails, did nothing wrong. They are
using R as intended, so there shouldn't be anything to fix. I think that
mixR::mixfitEM is making a mistake in its use o...