Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6087873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:55:12+00:00 2026-05-23T11:55:12+00:00

How do I partially bind/apply arguments to a function in R? This is how

  • 0

How do I partially bind/apply arguments to a function in R?

This is how far I got, then I realized that this approach doesn’t work…

bind <- function(fun,...)
{
  argNames <- names(formals(fun))
  bindedArgs <- list(...)
  bindedNames <- names(bindedArgs)
  function(argNames[!argNames %in% bindedArgs])
   {
   #TODO
  }
}

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T11:55:12+00:00Added an answer on May 23, 2026 at 11:55 am

    Have you tried looking at roxygen’s Curry function?

    > library(roxygen) 
    > Curry
    function (FUN, ...) 
    {
        .orig = list(...)
        function(...) do.call(FUN, c(.orig, list(...)))
    }
    <environment: namespace:roxygen>
    

    Example usage:

    > aplusb <- function(a,b) {
    +   a + 2*b
    + }
    > oneplusb <- Curry(aplusb,1)
    > oneplusb(2)
    [1] 5
    

    Edit:
    Curry is concisely defined to accept named or unnamed arguments, but partial application of fun to arguments by way of formal() assignment requires more sophisticated matching to emulate the same functionality. For instance:

    > bind <- function(fun,...)
    + {
    +   argNames <- names(formals(fun))
    +   boundArgs <- list(...)
    +   boundNames <- names(boundArgs)
    +   if(is.null(boundNames)) {
    +     formals(fun)[1:length(boundArgs)] <- boundArgs
    +   } else {
    +     formals(fun)[match(names(boundArgs),argNames)] <- boundArgs
    +   }
    +   fun
    + }
    > oneplusb <- bind(aplusb,1)
    > oneplusb(2)
    Error in 2 * b : 'b' is missing
    

    Because the first argument in this function is still a, you need to specify which argument 2 is intended for (b=), or pass it as the second argument.

    > oneplusb
    function (a = 1, b) 
    {
        a + 2 * b
    }
    > oneplusb(b=2) ## or oneplusb(,2)
    [1] 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is currently said that MD5 is partially unsafe. Taking this into consideration, I'd
Using boost-bind , the resulting boost-function may receive more arguments than the bound object
My question is partially inspired by this article written by Eric Lippert: http://blogs.msdn.com/ericlippert/archive/2009/10/19/what-is-this-thing-you-call-thread-safe.aspx Using
I had a problem that was partially solved. To explain it quickly : I
I have a situation that has been partially covered by other answers at SO,
The tabexpansion function only works partially when I override it like so: function tabexpansion
I'm using entity framework and i have a problem that this dropdown ignores my
I currently have a partial-application function which looks like this: Function.prototype.curry = function() {
I recently read this blog entry by Hadi Hariri: That dreaded M in ASP.NET
I can bind a ListBox like this: XAML: <UserControl x:Class=TestDynamicForm123.Views.ViewCustomers xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml> <StackPanel Margin=10>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.