Fwd: Re: [R] couldn't find function ...

markhall@gol.com markhall at gol.com
Thu Jul 6 08:07:52 CEST 2000


Forwarded Message:

> To: Steve Arthur <sarthur at crick.protogene.com>

> From: Thomas Lumley <thomas at biostat.washington.edu>

> Subject: Re: [R] couldn't find function "..."

> Date: Wed, 5 Jul 2000 16:16:25 -0700 (PDT)

> -----

> On Wed, 5 Jul 2000, Steve Arthur wrote:
> 
> > Hi,
> > 
> > R 1.0.1, on Linux(mandrake/RedHat).
> > 
> > I am trying to write my first function using R and I need help figuring
> > out the error I have indicated in the Subject line above.  The purpose
> > of the function is not to "wow" anyone, but just to serve as a stepping
> > stone so that I might write more complicated functions in the future.
> > 
> > First I created my function named "CIfunc" and saved into the current
> > directory using the "save" command.
> > 
> > function(Mean, SD, N, Sig) {
> > 
> >    if (N > 30) { Zscore <- pnorm(Sig)} else {Zscore <- pt(Sig,N-1)}
> >    Zscore
> > 
> >    UpperCI <- Mean + Zscore * SD / sqrt(N)
> >    UpperCI
> > 
> >    LowerCI <- Mean - Zscore * SD / sqrt(N)
> >    LowerCI
> > 
> > }
> > 
> > ...with no error.
> > 
> > Next I write the function call "testcall":
> > 
> > testcall <- call('CIfunc', prescan10$F532Mean, prescan10$F532SD,
> > prescan10$FPixels, 0.95)
> > 
> > ...with no error.
> > 
> > testcall CIfunc(c(189, 238, 363, 869, 585, 350, 3624, 290, 436, 517),
> > c(63, 58, 66, 127, 78, 46, 1452, 72, 83, 55), c(120, 120, 120, 120, 120,
> > 120, 120, 120, 120, 120), 0.95)
> > 
> > But when I try to evaluate the function "CIfunc":
> > 
> > eval(testcall)
> > 
> > I get the error:
> > 
> > "Error in eval(expr, envir, enclos) : couldn't find function "CIfunc""
> > 
> > As I understand it, I saved the "CIfunc" in the directory I opened R from.
> > 
> > Do I need to set an environment variable to use functions in R?
> > 
> 
> Unless you're trying to do something very complicated that I don't
> understand this is a lot simpler than you're making it.
> 
> You don't have to write the function to a file. You don't need to use
> call(), and you don't need eval().
> 
> You just want to type
> 
> CIfunc(prescan10$F532Mean, prescan10$F532SD, prescan10$FPixels, 0.95)
> 
> 
> It's not clear why your function didn't work, but I suspect it's what
> Peter Dalgaard suggested.  You need to have the function defined in the
> workspace -- having it on disk doesn't help at all.
> 
> The point of call() and eval() is to allow functions to manipulate other
> functions and expressions, which is an important part of the language,
> but probably not an ideal subject for your first function. :)
> 
> 
> 	-thomas
> 
> -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
-
> r-help mailing list -- Read <a href="http://www.ci.tuwien.ac.at/~hornik/R/R-
FAQ.html">http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html</a>
> Send "info", "help", or "[un]subscribe"
> (in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
> 
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
> 


-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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