reference-class

how do I document an R Reference Class?

拈花ヽ惹草 提交于 2019-12-03 07:41:40
how do I document the use of member functions of a reference class? if I write a Rd file with a \usage block, how do I avoid the WARNING Functions/methods with usage in documentation object 'XmlDoc' but not in code: $ new I'd expect the \usage block to allow me write things like: obj <- ClassName$new(par1, par2, ...) obj$method1(oth1, ...) and then I'd document the parameters in the \arguments block. If I do this, R CMD check complains with Assignments in \usage in documentation object 'ClassName': and does not recognize the methods as code objects I need document. as of now, I am writing Rd

Reference Class with custom field classes in R?

久未见 提交于 2019-12-03 03:41:56
I would like to use a custom reference class inside another reference class, but this code fails: nameClass <- setRefClass("nameClass", fields = list(first = "character", last = "character"), methods = list( initialize = function(char){ chunks <- strsplit(char,"\\.") first <<- chunks[[1]][1] last <<- chunks[[1]][2] }, show = function(){ cat("Special Name Class \n:") cat("First Name:") methods::show(first) cat("Last Name:") methods::show(last) } )) # this works fine nameClass$new("tyler.durden") When I try to add a second class that has a field of class nameClass this class cannot be initiated.

Implementing standard software design patterns (focus on MVC) in R

半城伤御伤魂 提交于 2019-12-03 01:17:56
问题 Currently, I'm reading a lot about Software Engineering, Software Design, Design Patterns etc. Coming from a totally different background, that's all new fascinating stuff to me, so please bear with me in case I'm not using the correct technical terminology to describe certain aspects ;-) I ended up using Reference Classes (a way of OOP in R) most of the time because object orientation seems to be the right choice for a lot of the stuff that I'm doing. Now, I was wondering if anyone has some

Error in initFields(scales = scales) : could not find function “initRefFields”

折月煮酒 提交于 2019-12-01 22:07:44
I have a ggplot2 plotting function as part of my code. The function works fine when the file is sourced as R code, however when I include this function in an R package (and of course I include ggplot2 and scales both in the DESCRIPTION and in the NAMESPACE files of the package) I am getting the following error: Error in initFields(scales = scales) : could not find function "initRefFields" The respective call of scales in the ggplot2 object is the following: + facet_wrap(~PV_Type, ncol = 1, scales = "free") + I run the latest R (3.2.0) and the latest ggplot2 (1.0.1) installed from source. A

parallel computations on Reference Classes

霸气de小男生 提交于 2019-12-01 17:13:11
I have a list of fairly large objects that I want to apply a complicated function to in parallel, but my current method uses too much memory. I thought Reference Classes might help, but using mcapply to modify them doesn't seem to work. The function modifies the object itself, so I overwrite the original object with the new one. Since the object is a list and I'm only modifying a small part of it, I was hoping that R's copy-on-modify semantics would avoid having multiple copies made; however, in running it, it doesn't seem to be the case for what I'm doing. Here's a small example of the base R

parallel computations on Reference Classes

≯℡__Kan透↙ 提交于 2019-12-01 16:27:23
问题 I have a list of fairly large objects that I want to apply a complicated function to in parallel, but my current method uses too much memory. I thought Reference Classes might help, but using mcapply to modify them doesn't seem to work. The function modifies the object itself, so I overwrite the original object with the new one. Since the object is a list and I'm only modifying a small part of it, I was hoping that R's copy-on-modify semantics would avoid having multiple copies made; however,

Reference Classes, tab completion and forced method definition

青春壹個敷衍的年華 提交于 2019-11-30 13:55:58
I am currently writing a package using reference classes. I have come across an issue which from reading various sources: Method initialisation in R reference classes Can't reliably use RefClass methods in Snowfall I gather is caused because reference methods are not all copied to every object in the class rather they are copied when first accessed. https://stat.ethz.ch/pipermail/r-devel/2011-June/061261.html As an example define: test <- setRefClass("TEST", fields = list( a = "numeric"), methods = list( addone = function(){ a <<- a+1 }, initialize = function(){ a <<- 1 } ) ) example <- test

Dynamically Generate Reference Classes

跟風遠走 提交于 2019-11-30 11:43:24
I'm attempting to generate reference classes within an R package on the fly, and it's proving to be fairly difficult. Here are the approaches I've taken and problems I've run into: I'm creating a package in which I hope to be able to dynamically read in a schema and automatically generate an associated reference class (think SOAP). Of course, this means I won't be able to define my reference classes before-hand in the package sources. I initially attempted to create a new class using a simple: myClass <- setRefClass("NewClassName", fields=list(fieldA="character")) which, of course, works fine

How to debug methods from Reference Classes?

为君一笑 提交于 2019-11-28 02:09:36
问题 How to debug a call like getFields? I tried library(debug); mtrace(AB.setFields) but nothing happend. Besides there are some better ways to define AB.setFields? AB.getFields<-function(){ return(list(name,var2)) } AB.setFields<-function(fields){ namevar<-names(fields) for(i in 1:length(fields)) do.call("<<-",list(namevar[i],fields[[i]])) } AB <- setRefClass("AB", fields=c(name="character", var2="factor"), methods=list(getFields=AB.getFields ,setFields=AB.setFields) ) a<-AB(name="abc",var2

In R, is it possible to suppress “Note: no visible binding for global variable”?

前提是你 提交于 2019-11-27 06:18:17
问题 I'm wondering if its possible to suppress these outputs in R which are cluttering up the console: Note: no visible binding for global variable '.->ConfigString' Note: no visible binding for '<<-' assignment to 'ConfigString' Here is the code (its a simple ReferenceClass to store configuration for an R project): # Reference Class to store configuration Config <- setRefClass("Config", fields = list( ConfigString = "character" ), methods = list( # Constructor initialize = function() {