Skip to content

Applying map_* on list of R6 objects #213

Closed

Description

@imanuelcostigan

Issue: map_* functions no longer works when calling an active binding of an R6 class.

Reprex:

Numbers <- R6::R6Class("Numbers",
  public = list(
    x = 100
  ),
  active = list(
    x2 = function(value) {
      if (missing(value)) return(self$x * 2)
      else self$x <- value/2
    },
    rand = function() rnorm(1)
  )
)

n1 <- Numbers$new()
n1[["x2"]]
# > [1] 200
n2 <- Numbers$new()
n2[["x2"]]
# > [1] 200
nn <- list(n1, n2)
purrr::map_dbl(nn, "x2")
# > Error: `x` must be a vector (not a environment)

Session:

> session_info()
Session info ------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.3.1 (2016-06-21)
 system   x86_64, darwin15.6.0        
 ui       RStudio (0.99.1246)         
 language (EN)                        
 collate  en_AU.UTF-8                 
 tz       Australia/Sydney            
 date     2016-07-03                  

Packages ----------------------------------------------------------------------------------------
 package   * version date       source        
 devtools  * 1.12.0  2016-06-24 CRAN (R 3.3.0)
 digest      0.6.9   2016-01-08 CRAN (R 3.3.0)
 magrittr    1.5     2014-11-22 CRAN (R 3.3.0)
 memoise     1.0.0   2016-01-29 CRAN (R 3.3.0)
 purrr       0.2.2   2016-06-18 CRAN (R 3.3.0)
 R6          2.1.2   2016-01-26 CRAN (R 3.3.0)
 Rcpp        0.12.5  2016-05-14 CRAN (R 3.3.0)
 rsconnect   0.4.3   2016-05-02 CRAN (R 3.3.0)
 withr       1.0.2   2016-06-20 CRAN (R 3.3.0)

Activity

  1. hadley commented on Mar 3, 2017

    @hadley
    Member

    Related to #200: extract_impl() needs to be taught about environments

  2. added a commit that references this issue on Jan 10, 2025
    1fde13d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions