Skip to content

Commit

Permalink
Added hook for lexacal scoping of formular. Formulas now contain the
Browse files Browse the repository at this point in the history
environment in which they are created, currently stored as the .Environment
attribute.  The environment should only be accessed by the function
formula.environment to allow the storage to be changed.  print.formula
has been modified to strip off the .Environment attribute for printing.


git-svn-id: https://svn.r-project.org/R/trunk@9413 00db46b3-68df-0310-9c12-caf00c1e9a41
  • Loading branch information
luke committed Jun 2, 2000
1 parent 8677fe1 commit a945ac8
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/include/Rinternals.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ extern SEXP R_TspSymbol; /* "tsp" */
extern SEXP R_LastvalueSymbol; /* ".Last.value" */
extern SEXP R_CommentSymbol; /* "comment" */
extern SEXP R_SourceSymbol; /* "source" */
extern SEXP R_DotEnvSymbol; /* ".Environment" */

/* Missing Values - others from Arith.h */
#define NA_STRING R_NaString
Expand Down
7 changes: 6 additions & 1 deletion src/library/base/R/models.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ formula.data.frame<- function (x, ...)
eval(ff)
}

print.formula <- function(x, ...) print.default(unclass(x), ...)
print.formula <- function(x, ...) {
attr(x, ".Environment") <- NULL
print.default(unclass(x), ...)
}

formula.environment <- function(x) attr(x,".Environment")

"[.formula" <- function(x,i) {
ans <- NextMethod("[")
Expand Down
1 change: 1 addition & 0 deletions src/main/model.c
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,7 @@ SEXP do_tilde(SEXP call, SEXP op, SEXP args, SEXP rho)
PROTECT(class = allocVector(STRSXP, 1));
STRING(class)[0] = mkChar("formula");
setAttrib(call, R_ClassSymbol, class);
setAttrib(call, R_DotEnvSymbol, rho);
UNPROTECT(2);
return call;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/names.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ static void SymbolShortcuts()
R_TspSymbol = install("tsp");
R_CommentSymbol = install("comment");
R_SourceSymbol = install("source");
R_DotEnvSymbol = install(".Environment");
}

extern SEXP framenames; /* from model.c */
Expand Down

0 comments on commit a945ac8

Please sign in to comment.