Dae-Jin Lee <dae-jin.lee <at> uc3m.es> writes:
>
>
> I would like to know how to include and "if" condition when this happen,
> could it be something like:
>
> myfun <- optim(....) # run my function
>
> ????
> if(myfun == ERROR) ..... # when the error message is "L-BFGS-B needs
> finite values of 'fn'
> ????
>
See ?try :
e.g.
myfun <- try(optim(...))
if (class(myfun)=="try-error") { ... whatever ...
} else {
... success ...
}
or tryCatch
this is FAQ 7.32 ...
cheers
Ben Bolker
______________________________________________
[email protected] 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.