Skip to content

zkamvar/inheritest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testing S4 inheritance

Travis-CI Build Status

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.

UPDATE

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

Installation

You can install it via github, and it should work:

devtools::install_github("zkamvar/inheritest")

When it works

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

When it doesn't work

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

About

Test of method inheritance

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages