r6

Multiple inheritance for R6 classes

旧城冷巷雨未停 提交于 2019-12-03 08:24:24
问题 Actual question What are my options to workaround the fact that R6 does not support multiple inheritance? Disclaimer I know that R is primarily a functional language. However, it does also have very powerful object-orientation built in. Plus: I don't see what's wrong with mimicking OOD principles/behavior when you know you're prototyping for an object-oriented language such as C#, Java, etc. your prototypes of apps need to be self-sufficient ("full stack" including DB-backends, business logic

Multiple inheritance for R6 classes

半世苍凉 提交于 2019-12-02 22:24:10
Actual question What are my options to workaround the fact that R6 does not support multiple inheritance ? Disclaimer I know that R is primarily a functional language. However, it does also have very powerful object-orientation built in. Plus: I don't see what's wrong with mimicking OOD principles/behavior when you know you're prototyping for an object-oriented language such as C#, Java, etc. your prototypes of apps need to be self-sufficient ("full stack" including DB-backends, business logic and frontends/UI) you have such great "prototyping technology" like R6 and shiny at your disposal

“User” constructor for R6 class in R

拟墨画扇 提交于 2019-12-02 02:26:12
I am learning how to use R6 classes (and in general R OO). In this tutorial I found an interesting way of presenting constructors. In section 6.3 a different kind of constructor is defined, returning a class instance with "new" called inside the function. That resembles the behavior of initializing a class object with a function that computes some stuff, and it would be useful for my purposes. I was wondering if this can be done in R6 as well, and, if so, if there are resources where I can learn how to do it properly. My example in S4 is as follows: ERes <- setClass("ERes", representation =

dynamically add function to r6 class instance

梦想与她 提交于 2019-11-28 08:43:33
I'm trying to forget refclasses (R5) and move to R6 but there is a problem with dynamic code. I would add a new function and it works in R5: clsTrn <- setRefClass("clsTrn", fields = list(x = "numeric"), methods = list( add_function = function(rcode) { eval(parse(text=rcode), envir=.self) } ) ) cls <- clsTrn$new(x=4) cls$x # [1] 4 cls$add_function("predict = function(y) {return(.self$x*y)}") cls$predict(3) #[1] 12 Similar code doesn't work for R6. library(R6) clsTrnR6 <- R6Class("clsTrnR6", lock=FALSE, public = list( x = NA, initialize = function(x) { self$x <- x }, add_function = function

dynamically add function to r6 class instance

亡梦爱人 提交于 2019-11-27 02:24:37
问题 I'm trying to forget refclasses (R5) and move to R6 but there is a problem with dynamic code. I would add a new function and it works in R5: clsTrn <- setRefClass("clsTrn", fields = list(x = "numeric"), methods = list( add_function = function(rcode) { eval(parse(text=rcode), envir=.self) } ) ) cls <- clsTrn$new(x=4) cls$x # [1] 4 cls$add_function("predict = function(y) {return(.self$x*y)}") cls$predict(3) #[1] 12 Similar code doesn't work for R6. library(R6) clsTrnR6 <- R6Class("clsTrnR6",

Sub-assign by reference on vector in R

给你一囗甜甜゛ 提交于 2019-11-26 20:36:46
问题 Can I use sub-assign by reference on atomic vectors somehow? Of course without wrapping it in 1 column data.table to use := . library(data.table) N <- 5e7 x <- sample(letters, N, TRUE) X <- data.table(x = x) upd_i <- sample(N, 1L, FALSE) system.time(x[upd_i] <- NA_character_) # user system elapsed # 0.11 0.06 0.17 system.time(X[upd_i, x := NA_character_]) # user system elapsed # 0.00 0.00 0.03 If R6 can help on that I'm open for R6 solution as it is one of my dep already. I've already checked