[R] Building a function

Florent BATY baty at biomserv.univ-lyon1.fr
Thu Aug 1 15:09:18 CEST 2002


  >On Thu, Aug 01, 2002 at 11:44:31AM +0200, Florent BATY wrote:
/>> Hello, /
/>> /
/>> Is it possible to build a function, a posteriori, by getting the names /
/>> of the arguments and the formula in a list or a vector ? When I use 
the /
/>> function as.function(), I don't know how to define explicitly the 
names /
/>> of my variables as formal arguments. /
/>> /
/>> Thanks /
/>> /
/>> /

 >Did you check with the example (in 'help(as.function)') ?

 >If yes, can you give more details ?

 >L.

I did actually but it haven't managed to solve my problem.
 From an "nls" object, I want to construct a function based on
    1) the formula:

    > summary(nlsED)$formula[[3]]
        (t < lag) * log10(x0) + (t > lag) * log10(x0 * exp(mu * (t -
        lag)))

    2) the arguments of this formula:
    > all.vars(summary(nlsED)$formula[[3]])
    [1] "t"   "lag" "x0"  "mu"

Next step should consist in declaring the names of these variables as 
the arguments of the function but I have an Error message:

    > 
as.function(c(alist(all.vars(summary(nlsED)$formula[[3]])),summary(nlsED)$formula[[3]]))
    Error in 
as.function.default(c(alist(all.vars(summary(nlsED)$formula[[3]])),  :
        invalid formal argument list for "function"

I managed to construct a function with no arguments in it:

    > as.function(c(summary(nlsED)$formula[[3]]))
    function ()
    (t < lag) * log10(x0) + (t > lag) * log10(x0 * exp(mu * (t -
        lag)))

But I can't define the arguments of this function.

Do you have any ideas ??

_______________________________________

Florent BATY
CNRS UMR 5558
Dynamique des Populations Bactériennes
Faculté de Médecine Lyon-Sud
69921 OULLINS, BP 12
FRANCE
tel : +33 (0)4 78 86 31 67
fax : +33 (0)4 78 86 31 49
_______________________________________



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