Please forgive me if my question is answered in Help FAQ no. 23481739... In language like C every variable must be declared before it can be used. In VBA, if a variable has not been declared it is assumed to be of a special type (Variant). In R (and Matlab) variables do not have to be declared. This is convenient, but in a large program one can make a typo which will be extremely difficult to find. In VBA one can use a special statement (Option Explicit) which does not allow using variables which have not been previously declared. As far as I remember this can also be done in Matlab (or at least there is a utility which can check whether your program uses undeclared variables). My question is: does such an option/utility exist in R? Thank you. Moshe.
See findGlobals in the codetools package. On 10/19/07, Moshe Olshansky <m_olshansky at yahoo.com> wrote:> Please forgive me if my question is answered in Help > FAQ no. 23481739... > > In language like C every variable must be declared > before it can be used. > In VBA, if a variable has not been declared it is > assumed to be of a special type (Variant). > In R (and Matlab) variables do not have to be > declared. This is convenient, but in a large program > one can make a typo which will be extremely difficult > to find. > In VBA one can use a special statement (Option > Explicit) which does not allow using variables which > have not been previously declared. As far as I > remember this can also be done in Matlab (or at least > there is a utility which can check whether your > program uses undeclared variables). > > My question is: does such an option/utility exist in > R? > > Thank you. > > Moshe. > > ______________________________________________ > R-help at r-project.org 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. >
On Thu, 18 Oct 2007, Moshe Olshansky wrote:> Please forgive me if my question is answered in Help > FAQ no. 23481739...If it were, we might well not forgive you -- the faq isn't *that* long. But it isn't.> In VBA one can use a special statement (Option > Explicit) which does not allow using variables which > have not been previously declared. As far as I > remember this can also be done in Matlab (or at least > there is a utility which can check whether your > program uses undeclared variables). > > My question is: does such an option/utility exist in > R? >The codetools package provides a tool that scans your code for undeclared variables. It is not perfect --- it has occasional false positives and false negatives -- but it is pretty good. -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley at u.washington.edu University of Washington, Seattle