r6

updating method definitions in R6 object instance

纵饮孤独 提交于 2019-12-23 16:53:23
问题 How can I update the method definition of an R6 class instance? S3 uses the current method defintion, as I would expect. With R5 (Reference Classes) I can use myInstance=myInstance$copy(). With R6 I tried myInstance = myInstance$clone() but myInstance$someMethod() still invokes the old code. I need this, when I load object instances from a dump created on a long-running process. I want to debug and change the code on an object state after a long-running computation. Therefore, I cannot just

Inconsistency of S4 dispatch behavior for R6 classes

邮差的信 提交于 2019-12-22 09:23:20
问题 Actual questions Shouldn't the fact that R6 classes inherit from (informal S3) class R6 allow the definition of S4 methods for signature arguments of that very class? As this is - AFAICT - not the case, what would be a workaround that is in line with current S3/S4 standards or that could somewhat be regarded as "best practice" in such situations? Background and example Reference Classes Consider the following example where you would like to define methods that dispatch on the superclass that

Documenting R6 classes and methods within R package in RStudio

北城以北 提交于 2019-12-22 02:03:15
问题 I am struggling with the documentation of an R6 class and its methods. My goal is to get the autocompletion in RStudio for the methods. At the moment, I only get the name of the method but no the help information I normally get using roxygen2 documenting a function with parameters etc. At the moment, this is my class: #' @importFrom R6 R6Class MQParameters <- R6::R6Class( 'MQParameters', public=list( initialize=function(file_path=NA) { private$location <- file_path mq_parameters <- read.delim

“User” constructor for R6 class in R

为君一笑 提交于 2019-12-20 02:58:24
问题 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

Roxygen2: “Error in loadNamespace(name) : there is no package called ‘testthat’”?

那年仲夏 提交于 2019-12-13 10:51:50
问题 This is a follow up from a previous question. How to integrate new R6Class functions stored in independent files into an existing R package? In summary, in trying to load a function stored in a file. I managed to do it by altering manually the NAMESPACE and Collate in the DESCRIPTION and rebuilding the package. However, I am sure this is not standard practice since the package already has a man folder and .Rd files created with roxygen2. However, when I try to use roxygen2 to manage my

osgi r6 service.component.annotations property list

爱⌒轻易说出口 提交于 2019-12-12 04:12:36
问题 maybe I am plain stupid, but how do I set a list in a property value? For example with the felix scr annotations, a servlet looked somewhat like this @Component(metatype = false) @SlingServlet( methods = { "GET", "POST" }, resourceTypes = "sling/servlet/default", selectors = { "size" }, paths = { "/some/stupid/path/.*" } with the new osgi service annotations @Component(service = Servlet.class, property = { "sling.servlet.methods=GET", "sling.servlet.methods=POST", "sling.servlet.resourceTypes

R, R6, Get Full Class Name from R6Generator Object

丶灬走出姿态 提交于 2019-12-06 09:23:21
In R6, How can I get the full list of class inheritances, without creating instances of the generator objects? Consider the following: A = R6::R6Class("Base",NULL) B = R6::R6Class("Top",inherit = A) class(B) #Returns 'R6ClassGenerator' B$classname #Returns 'Top' What I want is c('Top','Base','R6') In other words, what would otherwise be returned by class(B$new()) In the real world, I have a complex set of inheritances, and, initializers with many arguments, some without default values, so I am trying to avoid instantiating a new object in order to obtain this information. There isn't a built

How to use `foreach` and `%dopar%` with an `R6` class in R?

百般思念 提交于 2019-12-06 02:38:10
I ran into an issue trying to use %dopar% and foreach() together with an R6 class. Searching around, I could only find two resources related to this, an unanswered SO question and an open GitHub issue on the R6 repository. In one comment (i.e., GitHub issue) an workaround is suggested by reassigning the parent_env of the class as SomeClass$parent_env <- environment() . I would like to understand what exactly does environment() refer to when this expression (i.e., SomeClass$parent_env <- environment() ) is called within the %dopar% of foreach ? Here is a minimal reproducible example: Work <- R6

Inconsistency of S4 dispatch behavior for R6 classes

社会主义新天地 提交于 2019-12-05 16:11:52
Actual questions Shouldn't the fact that R6 classes inherit from (informal S3) class R6 allow the definition of S4 methods for signature arguments of that very class? As this is - AFAICT - not the case, what would be a workaround that is in line with current S3/S4 standards or that could somewhat be regarded as "best practice" in such situations? Background and example Reference Classes Consider the following example where you would like to define methods that dispatch on the superclass that all instances of Reference Classes inherit from ( envRefClass ): TestRefClass <- setRefClass(

Documenting R6 classes and methods within R package in RStudio

懵懂的女人 提交于 2019-12-04 23:35:47
I am struggling with the documentation of an R6 class and its methods. My goal is to get the autocompletion in RStudio for the methods. At the moment, I only get the name of the method but no the help information I normally get using roxygen2 documenting a function with parameters etc. At the moment, this is my class: #' @importFrom R6 R6Class MQParameters <- R6::R6Class( 'MQParameters', public=list( initialize=function(file_path=NA) { private$location <- file_path mq_parameters <- read.delim(file_path, stringsAsFactors=FALSE) mq_parameters <- setNames(mq_parameters$Value, mq_parameters