-
-
Save yutannihilation/98ca0d9eb50ad4386f79 to your computer and use it in GitHub Desktop.
R6を試したメモ
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(R6) | |
methods(class = "R6") | |
#> [1] print.R6* | |
#> | |
#> Non-visible functions are asterisked | |
Numbers <- 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) | |
) | |
) | |
n <- Numbers$new() | |
# タブ補完は利かない | |
n$x | |
#> [1] 100 | |
names(n) | |
#> NULL | |
ls(n) | |
#> [1] "rand" "x" "x2" | |
as.list(n) | |
#> Error in as.vector(x, "list") : | |
#> cannot coerce type 'environment' to vector of type 'list' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment