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

  • SEARCH
  • Home
  • 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 8846801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:05:30+00:00 2026-06-14T12:05:30+00:00

I have a question which is an extension of another question . I am

  • 0

I have a question which is an extension of another question.

I am wanting to be able to pipeline anonymous functions. In the previous question the answer to pipeline defined functions was to create a pipeline operator “%|>%” and to define it this way:

"%|>%" <- function(fun1, fun2){
              function(x){fun2(fun1(x))}
}

This would allow you to call a series of functions while continually passing the result of the previous function to the next. The caveat was that the functions to to be predefined. Now I’m trying to figure how to do this with anonymous functions. The previous solution which used predefined functions looks like this:

square <- function(x){x^2}
add5 <- function(x){x + 5}

pipelineTest <-
  square %|>%
  add5

Which gives you this behviour:

> pipelineTest(1:10)
 [1]   6   9  14  21  30  41  54  69  86 105

I would like to be able to define the pipelineTest function with anonymous functions like this:

anonymousPipelineTest <-
  function(x){x^2} %|>%
  function(x){x+5} %|>%
  x

When I try to call this with the same arguments as above I get the following:

> anonymousPipelineTest(1:10)
function(x){fun2(fun1(x))}
<environment: 0x000000000ba1c468>

What I’m hoping to get is the same result as pipelineTest(1:10). I know that this is a trivial example. What I’m really trying to get at is a way to pipeline anonymous functions. Thanks for the help!

  • 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-06-14T12:05:30+00:00Added an answer on June 14, 2026 at 12:05 pm

    Using Compose, and calling the resulting function gives this:

    "%|>%" <- function(...) Compose(...)()
    

    Now get rid of the ‘x’ as the final “function” (replaced with an actual function, that is not needed but here for example):

    anonymousPipelineTest <-
         function(x){x^2} %|>%
         function(x){x+5} %|>% function(x){x}
    anonymousPipelineTest(1:10)
    
    [1]   6   9  14  21  30  41  54  69  86 105
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is an extension to a previous question which was answered. But have a
Hey guys i have a question which i have been looking for the answer
I have few Question for which I am not able to get a proper
I have a question which I am sure is simple but I have slight
I have a question which is slightly similar to this question on stackoverflow std::cin.clear()
I have a question which is described below: What problems would arise for testing
I have a question which I think involves conditional entropy in the field of
I have a question which may be somewhat silly because I'm pretty sure I
I have a question which involves calling a function with 2 parameters of a
this is my first time posting here, I have a question which I have

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.