Closed HenrikBengtsson closed 8 years ago
One reason is for instance if someone uses getElement()
on an Object, cf.
> getElement
function (object, name)
{
if (isS4(object))
methods::slot(object, name)
else object[[name, exact = TRUE]]
}
<bytecode: 0x2349a08>
<environment: namespace:base>
which gives an error with R.oo (<= 1.20.0);
> library("R.oo")
> obj <- Object()
> obj$abc <- 1
> getElement(obj, "abc")
Error in `[[.Object`(object, name, exact = TRUE) :
unused argument (exact = TRUE)
The exact
argument goes back to at least R 2.11.0 and since R.oo requires R (>= 2.13.0) we can safely add it to the package without having to worry about backward compatibility.
Added to develop branch; the following now works:
> library("R.oo")
> obj <- Object()
> obj$abc <- 1
> getElement(obj, "abc")
1
> getElement(obj, "abcd")
NULL
> obj[["abc"]]
[1] 1
> obj[["abc", exact=TRUE]]
However, argument exact
is currently ignored, e.g.
> obj[["abc", exact=FALSE]]
[1] 1
> obj[["ab", exact=FALSE]]
NULL
This required:
o Now $() for Object and Class calls [[() for ditto (was vice versa).
which may cause problems downstreams, e.g. infinite recursive call loop;
22: getFile.GenericDataFileSet(x, i, ...)
21: getFile(x, i, ...)
20: `[[.GenericDataFileSet`(this, files)
19: `$.Object`(this, files)
18: this$files
17: getFile.GenericDataFileSet(x, i, ...)
16: getFile(x, i, ...)
15: `[[.GenericDataFileSet`(this, files)
14: `$.Object`(this, files)
13: this$files
12: getFiles.GenericDataFileSet(this)
11: getFiles(this)
Thus, more care needs to be put into this.
R's
[[()
gained argumentexact = TRUE
a while ago (not sure in which version). For example:Action
Add an
exact
argument for[[.Object
as well, or at least...
such that it doesn't give an error if it is passed.