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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:03:01+00:00 2026-05-27T13:03:01+00:00

My question is the following. Given the following function: spam <- function() { cat(eggs\n)

  • 0

My question is the following. Given the following function:

spam <- function() {
  cat("eggs\n")
}

bla <- spam()

I want to find the name of the object the function is returning its content to. In the example bla <- spam() this would be bla. Using match.call I can find the call that was performed:

match.call()
function() {
      cat("eggs\n")
    }   

this, however, does not include the name of the object the function returns to. I’ve looked around on the R-help list, google and SO, but could not find anything useful. Any suggestions how to proceed?

Background
From the replies I gather that what I want is a bit on the esotheric side. I’d explain where I’m coming from, this might shed some light on my motives. The context I’m working in has to do with testing, and more specifically, testing whether or not a certain object changes in time (e.g. model output).

Normally a user will write a bunch of code that generates an object, save it and compare the saved object to newly generated objects as time goes on. The user can do this using the following function:

spam <- testReferenceChange(expression)

Normally this function will read the reference and generate a new object, which the user can compare to each other. For regenerating the reference file, I wanted to use the exact same code. I do this by changing a global option (see options and getOption), recalculate. We running this function in the recalculation mode, new references are stored. And now for the reason to my question. In saving the reference to file (using save()) I wanted to use the name of the object the user returns to, combined with a date, to create a unique name.

  • 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-27T13:03:02+00:00Added an answer on May 27, 2026 at 1:03 pm

    …I find it hard to imagine why you would want this. Also, your spam function returns NULL so it seems even more pointless…

    Nevertheless, the simplest/cleanest way to do this is to pass in the name to the spam function!

    spam <- function(name) {
       cat(name, "<- eggs\n")
       42 # return a value
    }
    
    
    bla <- spam("bla")
    

    Advancing to the next level, you could have spam do the assignment. You can also play with substitute to allow specifying the name without quotes:

    spam <- function(name) {
       name <- as.character(substitute(name))
       cat(name, "<- eggs\n")
       value <- 42
       assign(name, value, parent.frame())
    }
    
    spam(bla)
    bla # 42
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Newbie question. Given the following html. <div id=mycontainer1 class=container> <input type=text class=name/> <input type=text
Could your please help me with following interview question. Given function ‪ Sleep(int seconds)
Let's say I want to write a function that does the following: Given a
Updated question given Andrew Hare's correct answer: Given the following C# classes: public class
I was given the following as an interview question: class A { public: void
This came up when answering another user's question (TheSoftwareJedi)... Given the following table: ROW_PRIORITY
A little stuck here. I have a simple question I guess. Given the following
Question: Given the following code snippet: bool foo(int n) { for(int i=3;i<sqrt(n)+0.5;i+=2) { if((n%i)==0){
Given the following sample code: $(document).ready(function(){ $(:input).blur(function(){ alert(The input type is: ); //How would
In a continuation from this question . I'm trying to bind a given function

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.