[R] Function assignment

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Mon Jul 28 16:17:11 CEST 2014


I am sorry but I don't follow your description beyond "use it with an external reference" because external references are external, while the destination of an assignment is an internal reference. If you want the destination to be an object which uses special knowledge (an external reference) to store the value (e.g. by an assignment function) into an external object, then the internal object should have PREVIOUSLY been constructed with that special knowledge about that external reference. Thus I don't follow why you want the external reference to be the destination of an assignment. The replace method seems much more suitable if you want to supply an external key in the course of the assignment.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at 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 28, 2014 1:59:18 AM PDT, Florian Ryan <florian.ryan at aim.com> wrote:
>
>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.ryan at aim.com
>
> 
>
> 
>
>-----Original Message-----
>From: peter dalgaard <pdalgd at gmail.com>
>To: Jeff Newmiller <jdnewmil at dcn.davis.ca.us>
>Cc: Florian Ryan <florian.ryan at aim.com>; r-help <r-help at 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 <jdnewmil at 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:<jdnewmil at 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.ryan at 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 at 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 at 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.mes at cbs.dk  Priv: PDalgd at gmail.com
>
>
>
>
>
>
>
>
>
>



More information about the R-help mailing list