I have a problem with basic inheritance of the [
operator for S4 objects that implement custom arguments. This is a working example from a stackoverflow post I created.
It was revealed as a bug in the callNextMethod()
implementation and has been fixed in the upcoming version of R!
https://github.com/wch/r-source/commit/0c06db284ec6d026040d464c3bfea66cf56a09b7
You can install it via github, and it should work:
devtools::install_github("zkamvar/inheritest")
It works if the package is built to your system
library("inheritest")
foo <- new("foo", x = pi, y = 2)
foo["x"]
#> FOOOOOOO
#> [1] 3.141593
foo["y", foo = FALSE]
#> [1] 2
bar <- new("bar", x = pi, y = 2, distance = 0)
bar["x"]
#> BAAAAAAR
#> FOOOOOOO
#> [1] 3.141593
bar["distance", bar = FALSE]
#> [1] 0
It doesn't work if the package is simply loaded:
In the shell:
git clone https://github.com/zkamvar/inheritest.git
cd inheritest
In R:
devtools::load_all(".")
#> Loading inheritest
foo <- new("foo", x = pi, y = 2)
foo["x"]
#> FOOOOOOO
#> [1] 3.141593
foo["y", foo = FALSE]
#> [1] 2
bar <- new("bar", x = pi, y = 2, distance = 0)
bar["x"]
#> BAAAAAAR
#> Error in callNextMethod(x, i, j, ..., drop): bad object found as method (class "function")
bar["distance", bar = FALSE]
#> [1] 0
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.