>Say I have argnames <- c("a", "b", "c").
>From that I want to construct the equivalent of alist(a=, b=, c=).
Here's a one liner that'll do that for you:
argnames <- letters[1:3]
setNames(rep(list(bquote()), length(argnames)), argnames)
- Josh
--
View this message in context:
http://r.78969
On Wed, Oct 3, 2012 at 9:37 PM, Peter Meilstrup
wrote:
> This is tangentially related to Hadley's question.
>
> Suppose I'm building a function programmatically; I have assembled an
> expression for the body and I know the names of the arguments it wants
> to take.
>
> Suppose I have some convenie
This is tangentially related to Hadley's question.
Suppose I'm building a function programmatically; I have assembled an
expression for the body and I know the names of the arguments it wants
to take.
Suppose I have some convenience function such that writing
make_function(alist(a=, b=), quot
> I think `function` does not eval its arguments, and it demands a
> pairlist. So this works:
>
> f <- eval(substitute(`function`(args, body),
> list(args=as.pairlist(alist(a=1)), body=quote(a+1
>
> The other thing to notice is a syntax difference between function and
> ordinary calls: when wri
On Wed, Oct 3, 2012 at 7:47 AM, Hadley Wickham wrote:
>> There is: it is `function`. The parser converts your function definitions
>> into a call to it. (It has 3 arguments: the formals, the body, and the
>> srcref. The environment is added when it is evaluated.)
>>
>> So your make_function be
On 10/3/2012 6:47 AM, Martin Morgan wrote:
On 10/02/2012 05:19 PM, Henrik Bengtsson wrote:
Hi,
I'm looking for a super-duper fast mean/sum binning implementation
available in R, and before implementing z = binnedMeans(x y) in native
code myself, does any one know of an existing function/package
>> | Is there a mechanism on R-forge for updating an existing
>> CRAN package, analogous to the 'submit to cran' link on the
>> R-forge package page,
> I prefer to do this 'by hand' but my understanding is that 'submit to cran'
> is equivalent to 'push this current version to CRAN' ---
On Oct 3, 2012, at 16:49 , Hadley Wickham wrote:
> On Wed, Oct 3, 2012 at 9:33 AM, Gabriel Becker wrote:
>> Hadley,
>>
>> You could do this:
>>
>> make_fun = function(args, body, env)
>> {
>> f = function()
>> formals(f) = args
>> body(f) = body
>> environment(f) = env
>> f
>> }
>>
>> If for
Err, typo: "function()" should of course say "function() {}"
~G
On Wed, Oct 3, 2012 at 7:49 AM, Hadley Wickham wrote:
> On Wed, Oct 3, 2012 at 9:33 AM, Gabriel Becker
> wrote:
> > Hadley,
> >
> > You could do this:
> >
> > make_fun = function(args, body, env)
> > {
> > f = function()
> > forma
On Wed, Oct 3, 2012 at 9:33 AM, Gabriel Becker wrote:
> Hadley,
>
> You could do this:
>
> make_fun = function(args, body, env)
> {
> f = function()
> formals(f) = args
> body(f) = body
> environment(f) = env
> f
> }
>
> If for some reason using function() itself as Duncan suggested won't work.
O
> There is: it is `function`. The parser converts your function definitions
> into a call to it. (It has 3 arguments: the formals, the body, and the
> srcref. The environment is added when it is evaluated.)
>
> So your make_function below is pretty similar (but because `function` is
> primitive
Hadley,
You could do this:
make_fun = function(args, body, env)
{
f = function()
formals(f) = args
body(f) = body
environment(f) = env
f
}
If for some reason using function() itself as Duncan suggested won't work.
Note: args will need to be the right kind of pairlist, eg what is returned
from a
On 03/10/2012 10:16 AM, Hadley Wickham wrote:
Hi all,
A function has three components: arguments, body and environment. Is
there no base function that allows us to create a function from those
three components?
There is: it is `function`. The parser converts your function
definitions into a
> Am I missing a built in way to do this? Also, is there a built in
> equivalent to my mquote (= multiquote, for producing a named list of
> quoted inputs)?
Oops, built in equivalent to mquote is alist. (It would be really
handy if that was referenced from quote)
Hadley
--
RStudio / Rice Univ
Hi all,
A function has three components: arguments, body and environment. Is
there no base function that allows us to create a function from those
three components?
The best I could come up with is:
make_function <- function(args, body, env = parent.frame()) {
args <- as.pairlist(args)
stopi
On 10/02/2012 05:19 PM, Henrik Bengtsson wrote:
Hi,
I'm looking for a super-duper fast mean/sum binning implementation
available in R, and before implementing z = binnedMeans(x y) in native
code myself, does any one know of an existing function/package for
this? I'm sure it already exists. So,
Look at rowsum. It's pretty fast C code.
Terry T
On 10/03/2012 05:00 AM, r-devel-requ...@r-project.org wrote:
Hi,
I'm looking for a super-duper fast mean/sum binning implementation
available in R, and before implementing z = binnedMeans(x y) in native
code myself, does any one know of an exis
17 matches
Mail list logo