\HeaderA{get.var}{Get named variable or evaluate expression from list or data.frame}{get.var}
\keyword{models}{get.var}
\keyword{smooth}{get.var}
\keyword{regression}{get.var}
\begin{Description}\relax
This routine takes a text string and a data frame or list. It first sees if the 
string is the name of a variable in the data frame/ list. If it is then the value of this variable is returned. 
Otherwise the routine tries to evaluate the expression within the data.frame/list (but nowhere else) and if 
successful returns the result. If neither step works then \code{NULL} is returned. The routine is useful for
processing gam formulae. If the variable is a matrix then it is coerced to a numeric vector, by default.
\end{Description}
\begin{Usage}
\begin{verbatim} get.var(txt,data,vecMat=TRUE)
\end{verbatim}
\end{Usage}
\begin{Arguments}
\begin{ldescription}
\item[\code{txt}] a text string which is either the name of a variable in \code{data} or when 
parsed is an expression that can be evaluated in \code{data}. It can also be neither in which case the
function returns \code{NULL}.
\item[\code{data}] A data frame or list.
\item[\code{vecMat}] Should matrices be coerced to numeric vectors?
\end{ldescription}
\end{Arguments}
\begin{Value}
The evaluated variable or \code{NULL}. May be coerced to a numeric vector if it's a matrix.
\end{Value}
\begin{Author}\relax
Simon N. Wood \email{simon.wood@r-project.org}
\end{Author}
\begin{References}\relax
\url{http://www.maths.bath.ac.uk/~sw283/}
\end{References}
\begin{SeeAlso}\relax
\code{\LinkA{gam}{gam} }
\end{SeeAlso}
\begin{Examples}
\begin{ExampleCode}
y <- 1:4;dat<-data.frame(x=5:10)
get.var("x",dat)
get.var("y",dat)
get.var("x==6",dat)
dat <- list(X=matrix(1:6,3,2))
get.var("X",dat)
\end{ExampleCode}
\end{Examples}

