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

using obj$set to create NULL object #158

Closed
yonicd opened this issue Sep 24, 2018 · 1 comment
Closed

using obj$set to create NULL object #158

yonicd opened this issue Sep 24, 2018 · 1 comment

Comments

@yonicd
Copy link

@yonicd yonicd commented Sep 24, 2018

I want to add a new public element with a value NULL in an R6Class using obj$set.

Intuitively I would do

obj$set('public','foo',NULL)

But the way obj$set is written if I want to add a new element with NULL value it is removed from the group list

self[[group]][[name]] <- value

Simple <- R6::R6Class("Simple",
                  public = list(
                    x = 1,
                    getx = function() self$x
                  )
)

Simple$set('public','foo',NULL)

Simple$public_fields
#> $x
#> [1] 1

Created on 2018-09-24 by the reprex package (v0.2.1)

It would need to be

value <- list(NULL)
self[[group]][name] <- value

If I put in obj$set('public','foo',list(NULL)) then I get back a list object which is not what I intended.

Simple <- R6::R6Class("Simple",
                  public = list(
                    x = 1,
                    getx = function() self$x
                  )
)

Simple$set('public','foo',list(NULL))

Simple$public_fields
#> $x
#> [1] 1
#> 
#> $foo
#> $foo[[1]]
#> NULL

Created on 2018-09-24 by the reprex package (v0.2.1)

Is there a way to do this now that I can't see?

@wch
Copy link
Member

@wch wch commented Sep 25, 2018

I agree that would make more sense for Simple$set('public', 'foo', NULL) to set foo to NULL than it would to remove foo. I'll make that change.

Loading

@wch wch closed this in 1c1f425 Sep 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants