[R] Problem with adapt package
Martin Maechler
maechler at stat.math.ethz.ch
Fri Jun 29 13:41:26 CEST 2001
>>>>> "JonR" == Jonathan Rougier <J.C.Rougier at durham.ac.uk> writes:
JonR> Hi Anthony,
JonR> Anthony Tate wrote:
>>
>> I am having problems using the adapt add on package to integrate a function
>> over 2 dimensions, using the following code.
>>
>> library(adapt)
>>
>> alb1 <- function(p,X,th,alpha){
>> y <- p[1]; z <- p[2]
>> c <- sqrt((X + z*tan(th))^2 + z^2)
>> r <- sqrt(c^2 + y^2)
>> exp(-alpha*r) / r^3
>> }
>>
>> x <- 0.05
>> y <- x
>> w <- 0.5
>> delta <- 0.1
>> czang <- pi/4
>> alpha <- 15.0
>> y[i] <- adapt(ndim=2, lower=c(0,0), upper=c(w,delta),
>> minpts=1000, maxpts=10^6, funct=alb1, eps=0.005,
>> X=x, th=czang, alpha=alpha)$value
>>
>> The code gives the following error
>>
>> Error in function (p, X, th, alpha) : Argument "X" is missing, with no default
JonR> This is a bug that I thought we had squashed. Crudely there is a
JonR> "..." missing in the line "ff<-functn". I have a feeling that
JonR> Martin fixed this with some tricky code using ".Alias", but the
JonR> fix has not appeared on CRAN. Martin?!
Yes, this definitely rings a bell! Indeed I had fixed something like that,
submitted to Thomas, who had put it into the integrate package then.
"adapt" has been packaged by Brian Ripley and I haven't checked whether
adapt() was the same as formerly in the integrate package...
Okay, yes, apply (something like) the following patch
--- R/adapt.R.~1~ Wed Jun 27 17:22:38 2001
+++ R/adapt.R Fri Jun 29 13:38:41 2001
@@ -7,12 +7,14 @@
keep.trying<-is.null(maxpts)
if (is.null(maxpts)) maxpts<-max(minpts,500)
- ## fudge for 1-d functions
- if (ndim == 1) {
+ if (ndim == 1) { ## fudge for 1-d functions
warning("Using integrate() in base R for 1-d integration")
return(integrate(functn,lower,upper,subdivisions=maxpts,rel.tol=eps,...))
}
- else ff<-functn
+ else ff <-
+ if(length(list(...)) && length(formals(functn)) > 1)
+ function(x) functn(x, ...)
+ else .Alias(functn)
## Check to make sure that upper and lower are reasonable lengths
## Both the upper and lower limits should be at least of length ndim
-----------
Note that the point is not in using .Alias() {which could be omitted},
but in the extra
if(length(list(...)) && length(formals(functn)) > 1)
function(x) functn(x, ...)
else
--
Martin Maechler <maechler at stat.math.ethz.ch> http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum LEO D10 Leonhardstr. 27
ETH (Federal Inst. Technology) 8092 Zurich SWITZERLAND
phone: x-41-1-632-3408 fax: ...-1228 <><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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