[Rd] substitute() on arguments in ellipsis ("dot dot dot")?
Hi. For any number of *known* arguments, we can do: one <- function(a) list(a = substitute(a)) two <- function(a, b) list(a = substitute(a), b = substitute(b)) and so on. But how do I achieve the same when I have: dots <- function(...) list(???) I want to implement this such that I can do: > exprs <- dots(1+2) > str(exprs) List of 1 $ : language 1 + 2 as well as: > exprs <- dots(1+2, "a", rnorm(3)) > str(exprs) List of 3 $ : language 1 + 2 $ : chr "a" $ : language rnorm(3) Is this possible to achieve using plain R code? Thanks, Henrik __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] substitute() on arguments in ellipsis ("dot dot dot")?
On 12/08/2018 4:00 PM, Henrik Bengtsson wrote: Hi. For any number of *known* arguments, we can do: one <- function(a) list(a = substitute(a)) two <- function(a, b) list(a = substitute(a), b = substitute(b)) and so on. But how do I achieve the same when I have: dots <- function(...) list(???) I want to implement this such that I can do: exprs <- dots(1+2) str(exprs) List of 1 $ : language 1 + 2 as well as: exprs <- dots(1+2, "a", rnorm(3)) str(exprs) List of 3 $ : language 1 + 2 $ : chr "a" $ : language rnorm(3) Is this possible to achieve using plain R code? I think so. substitute(list(...)) gives you a single expression containing a call to list() with the unevaluated arguments; you can convert that to what you want using something like dots <- function (...) { exprs <- substitute(list(...)) as.list(exprs[-1]) } Duncan Murdoch __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] substitute() on arguments in ellipsis ("dot dot dot")?
On Sun, Aug 12, 2018 at 10:00 PM, Henrik Bengtsson wrote: > Hi. For any number of *known* arguments, we can do: > > one <- function(a) list(a = substitute(a)) > two <- function(a, b) list(a = substitute(a), b = substitute(b)) > > and so on. But how do I achieve the same when I have: > > dots <- function(...) list(???) > > I want to implement this such that I can do: > >> exprs <- dots(1+2) >> str(exprs) > List of 1 > $ : language 1 + 2 > > as well as: > >> exprs <- dots(1+2, "a", rnorm(3)) >> str(exprs) > List of 3 > $ : language 1 + 2 > $ : chr "a" > $ : language rnorm(3) > > Is this possible to achieve using plain R code? You could use match.call, for example: dots <- function(...) match.call(expand.dots = FALSE)[['...']] Note that this returns a pairlist, so if you want an ordinary list you should wrap it in as.list() __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
[Rd] Package compiler - efficiency problem
Dear R team, I am a co-author and maintainer of one of R packages distributed by R-forge (gEcon). One of gEcon package users found a strange behaviour of package (R froze for couple of minutes) and reported it to me. I traced the strange behaviour to compiler package. I attach short demonstration of the problem to this mail (demonstration makes use of compiler and tictoc packages only). In short, the compiler package has problems in compiling large functions - their compilation and execution may take much longer than direct execution of an uncompiled function. Such functions are generated by gEcon package as they describe steady state for economy. I am curious if you are aware of such problems and plan to handle the efficiency issues. On one of the boards I saw that there were efficiency issues in rpart package but they have been resolved. Or would you advise to turn off JIT on package load (package heavily uses such long functions generated whenever a new model is created)? Best regards, Karol Podemski possible_bug_report.tar.gz Description: GNU Zip compressed data __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Re: [Rd] substitute() on arguments in ellipsis ("dot dot dot")?
Interestingly, as.list(substitute(...())) also works. On Sun, Aug 12, 2018 at 1:16 PM, Duncan Murdoch wrote: > On 12/08/2018 4:00 PM, Henrik Bengtsson wrote: >> >> Hi. For any number of *known* arguments, we can do: >> >> one <- function(a) list(a = substitute(a)) >> two <- function(a, b) list(a = substitute(a), b = substitute(b)) >> >> and so on. But how do I achieve the same when I have: >> >> dots <- function(...) list(???) >> >> I want to implement this such that I can do: >> >>> exprs <- dots(1+2) >>> str(exprs) >> >> List of 1 >> $ : language 1 + 2 >> >> as well as: >> >>> exprs <- dots(1+2, "a", rnorm(3)) >>> str(exprs) >> >> List of 3 >> $ : language 1 + 2 >> $ : chr "a" >> $ : language rnorm(3) >> >> Is this possible to achieve using plain R code? > > > I think so. substitute(list(...)) gives you a single expression containing > a call to list() with the unevaluated arguments; you can convert that to > what you want using something like > > dots <- function (...) { > exprs <- substitute(list(...)) > as.list(exprs[-1]) > } > > Duncan Murdoch > > > __ > R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel __ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel