Thank you very much!

The idea was to use it with an external reference and kind of to write an 
constructor 
for an object which points at this external reference and behaves like an R 
object.

So it would be the same as if I do just
name <- function("name", someValuesForObjectConstruction)
but I don't have to provide the names twice.
Where function returns an object which stores the string "name"
and knows get, set, ...

and since with 
setReplaceMethod(f="[", signature="myExternList",
    definition=function(x, i="character", j="missing", y){
    setExternReference(i, y)
    return(x)   
}

I can get nicely the name inside the bracket (x["name"] <- )
it seemed possible to get "name" some how out of an name <-
assignment.

Again thank you very much for hints and advice.

 

Florian Ryan
florian.r...@aim.com

 

 

-----Original Message-----
From: peter dalgaard <pda...@gmail.com>
To: Jeff Newmiller <jdnew...@dcn.davis.ca.us>
Cc: Florian Ryan <florian.r...@aim.com>; r-help <r-help@r-project.org>
Sent: Sat, Jul 26, 2014 10:04 pm
Subject: Re: [R] Function assignment



On 26 Jul 2014, at 17:01 , Jeff Newmiller <jdnew...@dcn.davis.ca.us> wrote:

> What an awful idea... that would lead to incredibly hard-to-debug programs. 
No, you cannot do that. What kind of problem has led you to want such a 
capability? Perhaps we can suggest a simpler way to think about your problem.

I agree that this is a silly idea, but I actually thought that it could be done 
by clever manipulation of the call stack. It can if you do the assignment with 
assign():

> foo <- function()sys.calls()[[1]][[2]]
> assign("z", foo())
> z
[1] "z"
> assign("bah", foo())
> bah
[1] "bah"

but if you do x <- foo(), there is no mention of x or "x" in sys.calls().

Anyways, functions that assume being called in a specific are asking for 
trouble 
in all cases where they get called differently.

-pd



> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<jdnew...@dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
>                                      Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
> --------------------------------------------------------------------------- 
> Sent from my phone. Please excuse my brevity.
> 
> On July 26, 2014 5:29:59 AM PDT, Florian Ryan <florian.r...@aim.com> wrote:
>> Hello,
>> 
>> I would like to use the variable name which i assign the return value
>> of a function in a function. Is that possible?
>> e.g.
>> 
>> foo <- function(){
>>   some not to me known R magic
>> }
>> 
>> myVariableName <- foo()
>> myVariableName
>> [1] "myVariableName"
>> 
>> Hope someone can help me.
>> 
>> Thanks
>> Florian
>> 
>>      [[alternative HTML version deleted]]
>> 
>> ______________________________________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
> 
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Email: pd....@cbs.dk  Priv: pda...@gmail.com









 


        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to