From murdoch@dunc@n @ending from gm@il@com  Mon Oct 15 18:01:59 2018
From: murdoch@dunc@n @ending from gm@il@com (Duncan Murdoch)
Date: Mon, 15 Oct 2018 12:01:59 -0400
Subject: [Rd] 
 sys.call() inside replacement functions incorrectly returns *tmp*
In-Reply-To: <CAB8pepwA52R9ZKOe7_83BMWzwsQcZ8eKG+wg3ihBL5+Qs5YPOQ@mail.gmail.com>
References: <CAB8pepwA52R9ZKOe7_83BMWzwsQcZ8eKG+wg3ihBL5+Qs5YPOQ@mail.gmail.com>
Message-ID: <d39892f6-99a3-eb78-b85b-8765d484a9c7@gmail.com>

On 14/10/2018 8:19 PM, Abs Spurdle wrote:
> Kia Ora
> 
> Let's say we have:
> "myreplacementfunction<-" = function (..., value)
> {	call = sys.call ()
> 	print (as.list (call) )
> 	0
> }
> 
> Then we call:
> x = 0
> myreplacementfunction (x, y, z) = 0
> 
> It will return:
> [[1]]
> `myreplacementfunction<-`
> 
> [[2]]
> `*tmp*`
> 
> [[3]]
> y
> 
> [[4]]
> z
> 
> $value
> <promise: 0x06fb6968>
> 
> There's two problems here.
> Firstly, x has to be defined otherwise we get an error message.
> Secondly, the first argument is returned as *tmp*.
> 
> Both are incorrect.

Both of these are documented (by example) in the R Language Definition 
manual, section 3.4.4:

"Assignment to subsets of a structure is a special case of a general 
mechanism for complex assignment:

x[3:5] <- 13:15
The result of this command is as if the following had been executed

`*tmp*` <- x
x <- "[<-"(`*tmp*`, 3:5, value=13:15)
rm(`*tmp*`)"

Duncan Murdoch

> 
> It should be possible to call the function without defining x.
> And it should return x rather than *tmp*.
> In other words, replacement function calls should be the same as other
> function calls.
> 
> Although it gets y and z right.
> 
> 
> kind regards
> Abs
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] sys.call() inside replacement functions incorrectly returns *tmp*
Duncan Murdoch