Sergio:
Fair question.
Unfair answer: My personal hangup. To my taste, get() makes R like a
macro language instead of doing functional programming. force() makes
me nervous about how I'm passing arguments. I won't attempt to defend
either of these claims, so feel free to dismiss.
Cheers,
Bert
O
Bert Gunter gene.com> writes:
> Another equivalent way to do it?
>
> f2 <- function(c,nm = "gamma",...)
> {
> probFunc <- paste0(c,nm)
> more <- list(...)
> function(x)do.call(probFunc,c(x,more))
> }
>
> This avoids the explicit use of get() and force(), I believe, but are
> there problem
se you intend to use the result of list(...) or c(...).
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
>
>> -Original Message-
>> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
>> Behalf
>> Of Julio Sergio
)) and f1 does.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Julio Sergio
> Sent: Wednesday, June 05, 2013 2:11 PM
> To: r-h...@stat.math.ethz.ch
William Dunlap tibco.com> writes:
> f1 <- function (c, nm = "gamma", ...)
> {
> probFunc <- getFunction(paste0(c, nm))
> force(list(...))
> function(x) probFunc(x, ...)
> }
>
> Bill Dunlap
> Spotfire, TIBCO Software
> wdunlap tibco.com
>
Thanks a lot William!, this really enhances m
or c(...).
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
> Behalf
> Of Julio Sergio
> Sent: Wednesday, June 05, 2013 1:26 PM
> To: r-h...@stat.math.ethz.ch
>
Bert Gunter gene.com> writes:
>
> faux <- function(c, nm = "gamma",...){
> f <- get(paste0(c,nm))
> function(x)f(x,...)
> }
>
> This could be called with:
>
> > xgam <- lapply(c("p","d"), faux, shape=k, scale=theta)
> > xgam[[1]](1000)
> [1] 0.8710477
> > xgam[[2]](1000)
> [1] 0
Rui et al.
Certainly correct.
However, I think the use of force() and similar should be avoided if
possible, as computing on the language can be tricky. So here is an
alternative formulation that avoids it:
faux <- function(c){
f <- get(paste0(c,"gamma")) ## evaluation of c is forced here
fu
Rui Barradas sapo.pt> writes:
> My solution works but it is incorrect. We should force the argument 'c',
>
> faux <- function(c) {
> force(c)
> function (x) get(paste0(c,"gamma"))(x,k,scale=theta)
> }
Thanks a lot, Rul. I think I have to learn a bit more about lazy evaluation
of a
Hello,
My solution works but it is incorrect. We should force the argument 'c',
not the return value. Like said in the help page for force. Which I've
only read after my first post. The following way makes much more sense
and is a bit shorter.
faux <- function(c) {
force(c)
f
Hello,
If in faux we ?force the return value, the bug is gone.
faux <- function(c) {
f <- function (x) get(paste0(c,"gamma"))(x,k,scale=theta)
force(f)
f
}
Hope this helps,
Rui Barradas
Em 05-06-2013 07:13, Michael Weylandt escreveu:
On Jun 5, 2013, at 3:53, Julio
On Jun 5, 2013, at 3:53, Julio Sergio wrote:
> I want to generate specific gamma distribution functions, given fixed
> parameters.
> This is I have k, and theta, say
>
> k <- 32.2549 # shape
> theta <- 26.32809 # scale
>
>
> # I have an auxiliary function that produces funcion
I want to generate specific gamma distribution functions, given fixed
parameters.
This is I have k, and theta, say
k <- 32.2549 # shape
theta <- 26.32809 # scale
# I have an auxiliary function that produces funcions according to
# a given character (this is to have either d
13 matches
Mail list logo