Skip to content

Instantly share code, notes, and snippets.

@chris-roerig
Last active July 18, 2017 13:57
Show Gist options
  • Save chris-roerig/982e3381b534dd04e4c6f40082eb1fe6 to your computer and use it in GitHub Desktop.
Save chris-roerig/982e3381b534dd04e4c6f40082eb1fe6 to your computer and use it in GitHub Desktop.
Simple R6 class in R
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