Dear R-helpers: (this is part of a bigger program) the following fails as a function, but runs OK if we comment out the fnfn_ function() line. Any hint would be appreciated. -Yudi- R : Copyright 1998, The R Development Core Team Version 0.63.0 Beta (Nov 13, 1998) -- on WIndows3.11 fnfn _ function (m=10,n=10,spar=2) { fn _ function(u,v){ uc_ u-floor(m/2)-1 vc_ v-floor(n/2)-1 exp(-(uc^2 + vc^2)/2/spar^2) } x1_ 1:m ; x2_ 1:n x12 _ outer(x1,x2,FUN='fn') filt _ x12/sum(x12) image(filt) }> source('fnfn.r') > m_10; n_10; spar_2 > fnfn(m,n,spar)Error in get(x, envir, mode, inherits) : variable "fn" was not found ------------------------------ Yudi Pawitan: yudi at ucd.ie Department of Statistics, UCD Dublin 4, Ireland Ph : 353-1-706 7641 Fax: 353-1-706 1186 ------------------------------ -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
On Thu, 21 Jan 1999 yudi at hermes.ucd.ie wrote:> Dear R-helpers: (this is part of a bigger program) > the following fails as a function, but runs OK > if we comment out the fnfn_ function() line. > Any hint would be appreciated. -Yudi- > > R : Copyright 1998, The R Development Core Team > Version 0.63.0 Beta (Nov 13, 1998) -- on WIndows3.11 > > fnfn _ function (m=10,n=10,spar=2) > { > fn _ function(u,v){ > uc_ u-floor(m/2)-1 > vc_ v-floor(n/2)-1 > exp(-(uc^2 + vc^2)/2/spar^2) > } > x1_ 1:m ; x2_ 1:n > x12 _ outer(x1,x2,FUN='fn') > filt _ x12/sum(x12) > image(filt) > }In both an old and the current development release you can fix this by removing the quotes around 'fn', or by using FUN=get("fn",mode="function") The problem is in outer(), in either the original or the current improved version. If FUN is a string we use get(FUN,mode="function"), which looks for FUN in the current environment and all parent environments. The problem is that "current" here means the environment in outer() or in match.fun(), not the environment outer() was called from. We probably need to fix match.fun() to take an environment parameter and outer() to then use match.fun(FUN,env=sys.frame(sys.parent())) Thomas Lumley Assistant Professor, Biostatistics University of Washington, Seattle. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
yudi at hermes.ucd.ie writes:> Dear R-helpers: (this is part of a bigger program) > the following fails as a function, but runs OK > if we comment out the fnfn_ function() line. > Any hint would be appreciated. -Yudi- > > R : Copyright 1998, The R Development Core Team > Version 0.63.0 Beta (Nov 13, 1998) -- on WIndows3.11 > > fnfn _ function (m=10,n=10,spar=2) > { > fn _ function(u,v){ > uc_ u-floor(m/2)-1 > vc_ v-floor(n/2)-1 > exp(-(uc^2 + vc^2)/2/spar^2) > } > x1_ 1:m ; x2_ 1:n > x12 _ outer(x1,x2,FUN='fn') > filt _ x12/sum(x12) > image(filt) > } > > > source('fnfn.r') > > m_10; n_10; spar_2 > > fnfn(m,n,spar)You want to get rid of the quotes around fn in the outer() call. If you pass a text string rather than the actual function, outer() will go looking for a function of that name in its own lexical scope and fail. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._