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 6067023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:33:48+00:00 2026-05-23T09:33:48+00:00

I am trying to call a function with a given string of the function

  • 0

I am trying to call a function with a given string of the function name.

E.g.

print(funcList)
[[1]]
`*`

[[2]]
sin

works:

mult <- `*`
mult(5,6)
[1] 30

doesn’t work:

func1 <- funcList[[1]]
func1(5,6)

func2 <- funcList[[2]]
func2(1.2)

So is it possible to call all of the functions in the functionList?

  • 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-23T09:33:49+00:00Added an answer on May 23, 2026 at 9:33 am

    Those don’t look like strings; that looks like a list of functions. To answer the question posed in your title, see get(). For example, using your list but stored as character strings:

    funcList <- list("*", "sin")
    

    we can use get() to return the function with name given by the selected element of the list:

    > f <- get(funcList[[1]])
    > f
    function (e1, e2)  .Primitive("*")
    > f(3,4)
    [1] 12
    

    An alternative is the match.fun() function, which given a string will find a function with name matching that string:

    > f2 <- match.fun(funcList[[1]])
    > f2(3,4)
    [1] 12
    

    but as ?match.fun tells us, we probably shouldn’t be doing that at the prompt, but from within a function.

    If you do have a list of functions, then one can simply index into the list and use it as a function:

    > funcList2 <- list(`*`, sin)
    > str(funcList2)
    List of 2
     $ :function (e1, e2)  
     $ :function (x)  
    > funcList2[[1]](3, 4)
    [1] 12
    > funcList2[[2]](1.2)
    [1] 0.9320391
    

    or you can save the functions out as interim objects, but there is little point in doing this:

    > f3 <- funcList2[[1]]
    > f3(3,4)
    [1] 12
    > f4 <- funcList2[[2]]
    > f4(1.2)
    [1] 0.9320391
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to call a function in JavaScript via Java. This works fine when
I'm trying to call a function with a variable name that is generated at
I'm trying to call a function, and VS gives me an error (red underline),
I'm trying to call a function after I load some XML into Actionscript, and
I'm trying to call a function inside another function in python, but can't find
I'm trying to call a function in a Python script from my main C++
I'm trying to call a function from a form within the same .php file,
I'm trying to call a function that contains jQuery code. I want this function
I am trying to call a function makeQuery and it's not working, FireBug is
I am trying to call my function named isUrgencyTypeValid from my javascript code but

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.