HenrikBengtsson / R.oo

R package: R.oo - R Object-Oriented Programming with or without References
https://cran.r-project.org/package=R.oo
20 stars 1 forks source link

Functions created by setConstructorS3() inside local({ ... }) does not work #3

Closed HenrikBengtsson closed 9 years ago

HenrikBengtsson commented 9 years ago

If using setConstructorS3() etc. within a local function/environment, then the corresponding static class instance cannot be found, which generates an error.

EXAMPLE:

library("R.oo")

local({

setConstructorS3("Foo", function() {
  extend(Object(), "Foo")
})

x <- Foo()
print(x)

})

The call to Foo() generates:

Error in getStaticInstance.Object(this, envir = ...envir) :
  Cannot get static instance. Failed to locate Class object for class 'Foo'.
HenrikBengtsson commented 9 years ago

Fixed: o BUG FIX: getStaticInstance() for Object now searches the parent/calling environment as well. This covers the case when constructors and objects are created in a local environment (contrary to package namespaces and the global environment).