Thanks a lot - f was renamed FF and things are OK
BW
Troels

-----Oprindelig meddelelse-----
Fra: Berwin A Turlach <berwin.turl...@gmail.com> 
Sendt: 19. december 2018 10:27
Til: Troels Ring <tr...@gvdnet.dk>
Emne: Re: [R] uniroot problem

G'day Troels,

On Wed, 19 Dec 2018 10:03:09 +0100
"Troels Ring" <tr...@gvdnet.dk> wrote:

> Dear friends and helpers - in the script below, uniroot is called with 
> a function CHB that calls a function, Charge. On its own, CHB 
> apparently does what is expected, but from within uniroot, problems 
> appear. An error is thrown
> 
> Error in f(lower, ...) : could not find function "f"
> 
> So CHB is not seen or understood from within uniroot?

Read the help page of uniroot.  

The first argument is called "f", it is the function for which the root is
searched.  In your call:

> uniroot(CHB,interval=c(1e-19,5),tol=.Machine$double.eps,maxiter=100000,
>              Na=Na,Cl=Cl,K=K,TOT=TOT,f=f)$root

You pass the object "f" (a vector "f <- c(1,1,1)" created earlier in your
code) to the argument "f".  Presumably there is no function called "f" in
your search path, and so R correctly complains that it cannot find the
function whose root you are looking for.

In R, arguments are passed first by exact matching of actual and formal
arguments, then by partial matching and then by position.

The easiest fix is probably to rename the object "f" to something else.

Cheers,

        Berwin

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to