Re: [R] adaptIntegrate - how to pass additional parameters to the integrand
Hi, The package maintainer is aware of this feature request. In the meantime, I've used Currying, require(cubature) f <- function(x, a) cos(2*pi*x*a) # a simple test function adaptIntegrate(roxygen::Curry(f, a=0.2), lower=0, upper=2) HTH, baptiste On 4 May 2011 05:57, Ravi Varadhan wrote: > Ok, I get it. > > require(cubature) > > f <- function(x, a) cos(2*pi*x*a) # a simple test function > > # this works > a <- 0.2 > adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2) > > # but this doesn't work > rm(a) > adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2, a=0.2) > > Ravi. > > > From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf > Of Uwe Ligges [lig...@statistik.tu-dortmund.de] > Sent: Tuesday, May 03, 2011 7:17 AM > To: HC > Cc: r-help@r-project.org > Subject: Re: [R] adaptIntegrate - how to pass additional parameters to the > integrand > > On 03.05.2011 06:43, HC wrote: >> Hello, >> >> I am trying to use adaptIntegrate function but I need to pass on a few >> additional parameters to the integrand. However, this function seems not to >> have the flexibility of passing on such additional parameters. >> >> Am I missing something or this is a known limitation. Is there a good >> alternative to such restrictions, if there at all are? > > > Looks like you are talking about the cubature package rather than about > base R. Frr the latter question: Please ask the package maintainer > rather than the list. Ideally send him code to implement the requested > feature and the maintainer will probably add your code. Not all package > maintainers read R-help. > > For an ad hoc solution: > > Just use > > adaptIntegrate(function(x, argA=a, argB=b) f(x, argA=argA, argB=argB), > ..) > > in order to set additional arguments for the function call. > > Uwe Ligges > > > > > > > > > > >> Many thanks for your time. >> HC >> >> >> -- >> View this message in context: >> http://r.789695.n4.nabble.com/adaptIntegrate-how-to-pass-additional-parameters-to-the-integrand-tp3491701p3491701.html >> Sent from the R help mailing list archive at Nabble.com. >> >> __ >> R-help@r-project.org mailing list >> 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. > > __ > R-help@r-project.org mailing list > 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. > __ > R-help@r-project.org mailing list > 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. > __ R-help@r-project.org mailing list 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.
Re: [R] adaptIntegrate - how to pass additional parameters to the integrand
Ok, I get it. require(cubature) f <- function(x, a) cos(2*pi*x*a) # a simple test function # this works a <- 0.2 adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2) # but this doesn't work rm(a) adaptIntegrate(function(x, argA=a) f(x, a=argA), lower=0, upper=2, a=0.2) Ravi. From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of Uwe Ligges [lig...@statistik.tu-dortmund.de] Sent: Tuesday, May 03, 2011 7:17 AM To: HC Cc: r-help@r-project.org Subject: Re: [R] adaptIntegrate - how to pass additional parameters to the integrand On 03.05.2011 06:43, HC wrote: > Hello, > > I am trying to use adaptIntegrate function but I need to pass on a few > additional parameters to the integrand. However, this function seems not to > have the flexibility of passing on such additional parameters. > > Am I missing something or this is a known limitation. Is there a good > alternative to such restrictions, if there at all are? Looks like you are talking about the cubature package rather than about base R. Frr the latter question: Please ask the package maintainer rather than the list. Ideally send him code to implement the requested feature and the maintainer will probably add your code. Not all package maintainers read R-help. For an ad hoc solution: Just use adaptIntegrate(function(x, argA=a, argB=b) f(x, argA=argA, argB=argB), ..) in order to set additional arguments for the function call. Uwe Ligges > Many thanks for your time. > HC > > > -- > View this message in context: > http://r.789695.n4.nabble.com/adaptIntegrate-how-to-pass-additional-parameters-to-the-integrand-tp3491701p3491701.html > Sent from the R help mailing list archive at Nabble.com. > > __ > R-help@r-project.org mailing list > 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. __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.
Re: [R] adaptIntegrate - how to pass additional parameters to the integrand
Dr. Ligges, Thanks a lot for providing syntax for passing additional parameters. It worked for me and has solved my problem. Many thanks for your quick help. HC -- View this message in context: http://r.789695.n4.nabble.com/adaptIntegrate-how-to-pass-additional-parameters-to-the-integrand-tp3491701p3492903.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.
Re: [R] adaptIntegrate - how to pass additional parameters to the integrand
On 03.05.2011 06:43, HC wrote: Hello, I am trying to use adaptIntegrate function but I need to pass on a few additional parameters to the integrand. However, this function seems not to have the flexibility of passing on such additional parameters. Am I missing something or this is a known limitation. Is there a good alternative to such restrictions, if there at all are? Looks like you are talking about the cubature package rather than about base R. Frr the latter question: Please ask the package maintainer rather than the list. Ideally send him code to implement the requested feature and the maintainer will probably add your code. Not all package maintainers read R-help. For an ad hoc solution: Just use adaptIntegrate(function(x, argA=a, argB=b) f(x, argA=argA, argB=argB), ..) in order to set additional arguments for the function call. Uwe Ligges Many thanks for your time. HC -- View this message in context: http://r.789695.n4.nabble.com/adaptIntegrate-how-to-pass-additional-parameters-to-the-integrand-tp3491701p3491701.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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. __ R-help@r-project.org mailing list 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.
[R] adaptIntegrate - how to pass additional parameters to the integrand
Hello, I am trying to use adaptIntegrate function but I need to pass on a few additional parameters to the integrand. However, this function seems not to have the flexibility of passing on such additional parameters. Am I missing something or this is a known limitation. Is there a good alternative to such restrictions, if there at all are? Many thanks for your time. HC -- View this message in context: http://r.789695.n4.nabble.com/adaptIntegrate-how-to-pass-additional-parameters-to-the-integrand-tp3491701p3491701.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list 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.