Last active
July 18, 2017 13:57
-
-
Save chris-roerig/982e3381b534dd04e4c6f40082eb1fe6 to your computer and use it in GitHub Desktop.
Simple R6 class in R
This file contains 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
require("R6") | |
MathTool <- | |
R6Class("MathTool", | |
public = list( | |
data = NULL, | |
initialize = function(data = c()){ | |
self$data <- data | |
}, | |
odds = function() { | |
odds <- c() | |
for(i in self$data) { | |
if(i %% 2 == 1) { | |
odds <- c(odds, i) | |
} | |
} | |
odds | |
}, | |
evens = function() { | |
evens <- c() | |
for(i in self$data){ | |
if(i %% 2 == 0){ | |
evens <- c(evens, i) | |
} | |
} | |
evens | |
} | |
) | |
) | |
tool <- MathTool$new(data = 1:10) | |
tool$evens() | |
tool$odds() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment