Skip to content
Prev 60826 / 63424 Next

stats::getInitial: requires the model to live in the stats namespace or above

Shouldn't the get()'s in stats:::getInitial.formula be looking in the
environment of the formula, not the environment of getInitial.formula?

--- selfStart.R (revision 82512)
+++ selfStart.R (working copy)
@@ -78,13 +79,19 @@
     switch (length(object),
             stop("argument 'object' has an impossible length"),
         {                              # one-sided formula
-           func <- get(as.character(object[[2L]][[1L]]))
+            if (!is.call(object[[2L]])) {
+                stop("Right-hand side of formula is not a call")
+            }
+           func <- get(as.character(object[[2L]][[1L]]), mode="function",
envir=environment(object))
            getInitial(func, data,
                       mCall = as.list(match.call(func, call =
object[[2L]])),
                        ...)
         },
         {                              # two-sided formula
-           func <- get(as.character(object[[3L]][[1L]]))
+            if (!is.call(object[[3L]])) {
+                stop("Right-hand side of formula is not a call")
+            }
+           func <- get(as.character(object[[3L]][[1L]]), mode="function",
envir=environment(object))
            getInitial(func, data,
                       mCall = as.list(match.call(func, call =
object[[3L]])),
                       LHS = object[[2L]], ...)

-Bill
On Wed, Jun 22, 2022 at 8:25 AM Ivan Krylov <krylov.r00t at gmail.com> wrote: