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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:51:22+00:00 2026-06-03T20:51:22+00:00

I am looking for the reverse of get() . Given an object name, I

  • 0

I am looking for the reverse of get().

Given an object name, I wish to have the character string representing that object extracted directly from the object.

Trivial example with foo being the placeholder for the function I am looking for.

z <- data.frame(x=1:10, y=1:10)

test <- function(a){
  mean.x <- mean(a$x)
  print(foo(a))
  return(mean.x)}

test(z)

Would print:

  "z"

My work around, which is harder to implement in my current problem is:

test <- function(a="z"){
  mean.x <- mean(get(a)$x)
  print(a)
  return(mean.x)}

test("z")
  • 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-03T20:51:23+00:00Added an answer on June 3, 2026 at 8:51 pm

    The old deparse-substitute trick:

    a<-data.frame(x=1:10,y=1:10)
    test<-function(z){
       mean.x<-mean(z$x)
       nm <-deparse(substitute(z))
       print(nm)
       return(mean.x)}
     
     test(a)
    #[1] "a"   ... this is the side-effect of the print() call
    #          ... you could have done something useful with that character value
    #[1] 5.5   ... this is the result of the function call
    

    Edit: Ran it with the new test-object

    Note: this will not succeed inside a local function when a set of list items are passed from the first argument to lapply (and it also fails when an object is passed from a list given to a for-loop.) You would be able to extract the ".Names"-attribute and the order of processing from the structure result, if it were a named vector that were being processed.

    > lapply( list(a=4,b=5), function(x) {nm <- deparse(substitute(x)); strsplit(nm, '\\[')} )
    $a      # This "a" and the next one in the print output are put in after processing
    $a[[1]]
    [1] "X"    ""     "1L]]"  # Notice that there was no "a"
    
    
    $b
    $b[[1]]
    [1] "X"    ""     "2L]]"
    
    > lapply( c(a=4,b=5), function(x) {nm <- deparse(substitute(x)); strsplit(nm, '\\[')} )
    $a
    $a[[1]]   # but it's theoretically possible to extract when its an atomic vector
    [1] "structure(c(4, 5), .Names = c(\"a\", \"b\"))" ""                                            
    [3] "1L]]"                                        
    
    
    $b
    $b[[1]]
    [1] "structure(c(4, 5), .Names = c(\"a\", \"b\"))" ""                                            
    [3] "2L]]"  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Q. Given [1,2,3] in Prolog get back [6,5,3] by reverse accumulation I have the
I was looking for a function that does the reverse of $this->db->escape() to get
I am looking for a function to reverse any string ( YYYYMDD , YY/MM/DD
Given this string: http://s.opencalais.com/1/pred/BusinessRelationType I want to get the last part of it: BusinessRelationType
I have a string which contains foos followed by numbers. I'm looking to print
I am looking for a method that reverses the same instance of a given
I am given 100 dollars and told that I have to do the following
I'm looking to get hold of different versions of taskmgr.exe from different versions of
I'm looking for the quickest/shortest way to get the first value from comma separated
I can't even copy and paste a strange checkmark looking character from my IDLE

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.