Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGZILLA #17496] methods::sealClass() does not work without specifying the 'where' argument #6670

Open
MichaelChirico opened this issue May 19, 2020 · 3 comments

Comments

@MichaelChirico
Copy link
Owner

Created attachment 2383 [details]
A patch for sealClass() generated as described in https://www.r-project.org/bugs.html.

Function sealClass() cannot be used without specifying the 'where' argument. This issue exists in R versions 2.15.1 through 3.5.0.

Here is an example of the bug in question:

setClass("foo", slots=c(name="character", age="integer"))
isSealedClass("foo")

[1] FALSE

sealClass("foo")

Error in list2env(list(), NULL, ) :
names(x) must be a character vector of the same length as x

isSealedClass("foo")

[1] FALSE

sealClass("foo", where=.GlobalEnv)
isSealedClass("foo")

[1] TRUE

This error occurs because sealClass() includes the following line:
if (missing(where)) where <- findClass(Class, unique = "sealing the class", where = where)

Because findClass() always returns a list (even if 'unique' contains a character string indicating that a unique location for the class is expected), this statement assigns a list of length 1, containing a single environment, to the variable 'where'.

This results in an error being thrown in the subsequent call to assignClassDef(), which expects the 'where' argument to contain an environment, rather than a list of environments:
assignClassDef(Class, classDef, where)

For this reason, the abovementioned line in sealClass() should instead read:
if (missing(where)) where <- findClass(Class, unique = "sealing the class", where = where)[[1]]

A patch for this bug is attached. Thanks very much for your assistance in this matter.


METADATA

  • Bug author - Adam Gower
  • Creation time - 2018-11-02 14:03:13 UTC
  • Bugzilla link
  • Status - ASSIGNED
  • Alias - None
  • Component - S4methods
  • Version - R 3.5.0
  • Hardware - All All
  • Importance - P5 normal
  • Assignee - Michael Lawrence
  • URL -
  • Modification time - 2018-11-02 16:00 UTC
@MichaelChirico
Copy link
Owner Author

Thanks, will commit.


METADATA

  • Comment author - Michael Lawrence
  • Timestamp - 2018-11-02 16:00:45 UTC

@github-actions
Copy link

github-actions bot commented Aug 7, 2020

NA


METADATA

  • Comment author - Sebastian Meyer
  • Timestamp - 2020-08-06 15:47:51 UTC

@github-actions
Copy link

NA


METADATA

  • Comment author - elin.waring
  • Timestamp - 2020-09-21 11:18:46 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant