[Rd] sys.call() inside replacement functions incorrectly returns *tmp*
Duncan Murdoch
murdoch@dunc@n @ending from gm@il@com
Mon Oct 15 18:01:59 CEST 2018
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 using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list