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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:38:41+00:00 2026-05-13T19:38:41+00:00

My question is how to extract the name of a variable from a function

  • 0

My question is how to extract the name of a variable from a function that is called in another function in R?

To illustrate, here is an example:

a <- function(variable) {

    print(deparse(substitute(variable)))

    internala(substitute(variable))

}

internala <- function(variableXX) {

    namex=deparse(substitute(variableXX))

    print(namex)
}

Calling the function a gives the following result:

>a(whatever)

[1] "whatever"

[1] "substitute(variable)"

which means that i can extract the name of the variable whatever from a, but not from internala.

Any thoughts on this?

Any help will be appreciated!

Maria

  • 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-13T19:38:42+00:00Added an answer on May 13, 2026 at 7:38 pm

    You could change a function to substitute argument of an internala function and eval it:

    a <- function(variable) {
        print(deparse(substitute(variable)))
        eval(substitute(internala(variable))) # this is only change
    }
    
    internala <- function(variableXX) {
        namex=deparse(substitute(variableXX))
        print(namex)
    }
    
    a(whatever)
    

    As hadley suggest its better to directly pass names. I usually do something like that:

    a <- function(variable, vname=deparse(substitute(variable))) {
        print(vname)
        internala(variable, vname)
    }
    
    internala <- function(variableXX, namex=deparse(substitute(variableXX))) {
        print(namex)
    }
    
    a(whatever)
    

    Each function could be call without passing name, but you can override it. For example:

    a(whatever, "othername")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following the directions at this question , I have some code running to extract
Question Can I build a image database/library that has an e-commerce style checkout system
Question Is there a way to have a method that will always run anytime
Example routine: const Armature* SceneFile::findArmature(const Str& name){ for (int i = 0; i <
I'm writing some quick code to try and extract data from an mp3 file
I had a controller POST action that is called List that accepts a status
My problem is :: From a string like /usr/folder1/folder2/filename.ext I have to extract out
I am trying to parse an XML to extract values of certain variables. Here's
it is probably a dummy question, but... I generate HTML document from a database.
here is my problem I have the following array (for example) string[] arr =

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.