[R] problems sourcing in vs interactive

Bill Simpson wsi at gcal.ac.uk
Mon Feb 19 15:22:38 CET 2001


If I source in the function (see below) calib(), I get:
> source("papers/helle/threshold.r")
> calib()
Error in eval(expr, envir, enclos) : Object "energy" not found

But if I cut and paste the code for calib() one line at a time into the R
window it works fine.

calib<-function()
{
contrast<-c(.01,.02,.0325,.055,.0775,.1,.125,.15,.175,.2)
energy<-c(3.53189e-5,.000141275,.000373056,.0010684,.00212134,.00353189,
.00551857,.00794675,.0108164,.0141275)
plot(contrast,energy)
fit<-nls(energy~a*contrast^2,start=list(a=.01))
contrastfit<-seq(min(contrast),max(contrast),length=40)
energyfit<-coef(fit)[[1]]*contrastfit^2
lines(spline(contrastfit,energyfit))
list(summary(fit))
#for these data, energy=.3532 * contrast^2 s deg^s
}

What is wrong and how to fix? The problem seems to originate in nls()
since the plot is produced OK: plot() can find the object "energy". I
think I have the nls() syntax right.

Thanks very much for any help.

Bill Simpson

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list