writing simple function through script
Its looking in environment(LgmFormula) for Xdata in order to evaluate Xdata$Qe in the weights argument so just specify weights = Qe. Alternately insert the following as the beginning of yo. It creates a new local LgmFormula but with its environment set to the current environment: environment(LgmFormula) <- environment() See the Environment section of ?formula On Wed, Sep 10, 2008 at 9:22 AM, Benoit Boulinguiez
<benoit.boulinguiez at ensc-rennes.fr> wrote:
Hi all,
I try to write a simple function in a script. The script is as follows
yo<-function(Xdata)
{
n<-length(Xdata[,1])
Lgm<-nls(formula=LgmFormula,
data=Xdata,
start=list(a=1500,b=0.1),weights=Xdata$Qe)
return(Lgm)
}
After the execution of the script, when I call the function yo on data
called NC60.DATA I get an error.
#yo(NC60.DATA)
Erreur dans eval(expr, envir, enclos) : objet "Xdata" not found
The object Xdata isn't found. Why?
Is that possible to debug a function with R?
Regards/Cordialement
-------------
Benoit Boulinguiez
Ph.D
Ecole de Chimie de Rennes (ENSCR) Bureau 1.20
Equipe CIP UMR CNRS 6226 "Sciences Chimiques de Rennes"
Campus de Beaulieu, 263 Avenue du G?n?ral Leclerc
35700 Rennes, France
Tel 33 (0)2 23 23 80 83
Fax 33 (0)2 23 23 81 20
http://www.ensc-rennes.fr/
[[alternative HTML version deleted]]
______________________________________________ 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.