[Rd] model.frame() call from inside a function (PR#3671)

Saikat DebRoy saikat at stat.wisc.edu
Thu Aug 7 11:24:17 MEST 2003


That attachment disappeared from the previous mail. Here is the patch I 
mentioned.

diff -Naur src/library/nls/R/nls.R /tmp/R/nls.R
--- src/library/nls/R/nls.R	Mon Jul 28 11:11:06 2003
+++ /tmp/R/nls.R	Thu Aug  7 10:04:49 2003
@@ -38,7 +38,7 @@

  nlsModel.plinear <- function( form, data, start ) {
      thisEnv <- environment()
-    env <- new.env()
+    env <- new.env(parent=environment(form))
      for( i in names( data ) ) {
          assign( i, data[[i]], envir = env )
      }
@@ -216,7 +216,7 @@
             },
             predict = function(newdata = list(), qr = FALSE)
             {
-               Env <- new.env()
+               Env <- new.env(parent=environment(form))
                 for (i in objects(envir = env)) {
                     assign(i, get(i, envir = env), envir = Env)
                 }
@@ -234,7 +234,7 @@

  nlsModel <- function( form, data, start ) {
      thisEnv <- environment()
-    env <- new.env()
+    env <- new.env(parent=environment(form))
      for( i in names( data ) ) {
          assign( i, data[[i]], envir = env )
      }
@@ -374,7 +374,7 @@
             Rmat = function() qr.R( QR ),
             predict = function(newdata = list(), qr = FALSE)
             {
-               Env <- new.env()
+               Env <- new.env(parent=environment(form))
                 for (i in objects(envir = env)) {
                     assign(i, get(i, envir = env), envir = Env)
                 }
@@ -398,7 +398,9 @@
              subset, weights, na.action)
  {
      mf <- match.call()             # for creating the model frame
+    env <- environment(formula)
      formula <- as.formula( formula )
+
      varNames <- all.vars(formula)  # parameter and variable names from 
formula

      ## adjust a one-sided model formula by using 0 as the response
@@ -435,7 +437,7 @@

      mf$formula <-                         # replace RHS by linear 
model formula
        parse( text = paste("~", paste( varNames[varIndex], collapse = 
"+")))[[1]]
-
+    environment(mf$formula) <- env
      mf$start <- mf$control <- mf$algorithm <- mf$trace <- NULL
      mf[[1]] <- as.name("model.frame")
      mf <- as.list(eval(mf, parent.frame()))



More information about the R-devel mailing list