Questions tagged [r6]

The R6 package provides a type of class which is similar to R’s standard reference classes, but it is more efficient and doesn’t depend on S4 classes and the methods package

181 questions
2
votes
0 answers

Can't override dynamically created method

Reproducible example: Parent <- R6::R6Class( "Parent", lock_objects = FALSE, public = list( initialize = function() { # I wan't to create many methods dynamically in the loop. self[["foo"]] <- function() { print('foo') …
Paweł Chabros
  • 2,349
  • 1
  • 9
  • 12
2
votes
2 answers

Is there a way/method to assign a R6 object to an S4 object slot?

As the topic describes I am looking for a way to achieve this: require("R6") R6cls <- R6::R6Class("R6obj", public = list(val = 1, foo = function() "foo!") ) # check this R6 class r6o <- R6cls$new() r6o # # Public: # clone: function…
GWD
  • 1,387
  • 10
  • 22
2
votes
2 answers

Preserve the structure of R data frame upon modification (in tidy pipelines)

I am working with data frames of a certain structure. For the sake of example, they are all expected to have an identical set of columns and unique values of the "id" column. There is also a set of S3 generics and methods for this class of data…
Dmitry Zotikov
  • 2,133
  • 15
  • 12
2
votes
1 answer

Link to R6 method from separate package in help pages and pkgdown

Cross posted from: https://community.rstudio.com/t/link-to-r6-method-from-separate-package-in-help-pages-and-pkgdown/134702 I'm currently writing an R package and would like to link to the help page for an R6 method in a separate package. The page I…
Jake Thompson
  • 2,591
  • 1
  • 16
  • 32
2
votes
1 answer

The fastest method to point an element in a nested list

Let's say we have an arbitrary size large nested list (the level of depth may exceed 100). The list contains objects (up to several thousand) in a non-predefined location in the list that we will need to see and modify often. Therefore, we keep a…
LordRudolf
  • 63
  • 8
2
votes
3 answers

Setting equivalent of .subset2 in R?

In R, I can use .subset2 to act as a [[ or $ without dispatch. > a <- new.env() > a$foo <- 3 > .subset2(a, "foo") [1] 3 However, I can't seem to find an equivalent for the setting operation without dispatch: > .subset2(a, "foo") <- 5 Error in…
Stefano Borini
  • 138,652
  • 96
  • 297
  • 431
2
votes
1 answer

How to correctly document R6 self

I have a function built with an R6class and was wondering the best way to pass devtools::check() is. Currently this repex gives the note > checking R code for possible problems ... NOTE obj_gen : : no visible binding for global variable…
Ben
  • 89
  • 7
2
votes
1 answer

Calling function of an R6 class within the initialize of R6

I am trying to build a reference implementation of our internal tooling for database connection boilerplate coding in R for other data scientists and data analyst Our software developers made something similar to this in python: class…
tfkLSTM
  • 161
  • 13
2
votes
1 answer

Access package-wide variable from within an R6 class

I am currently packaging up an API wrapper in R and found myself in a scenario in which I need to access a package-wide variable from within an R6 class (as it'll be used for a simple string concatenation). Below you can find an exemplification of…
anddt
  • 1,589
  • 1
  • 9
  • 26
2
votes
1 answer

How to select a subset of elements of the input R6 class within a shiny module to perform operations on them

Can I access a list of all input widgets within a module (let us name it myModule) and check if their state is isTruthy(). I found a way that works when I know (or can deduce) the exact names of the widgets (see 1). All_Inputs <-…
Jan
  • 4,974
  • 3
  • 26
  • 43
2
votes
1 answer

R fable::model() "turn on" progress bar

How do I "turn on" the progress bar for slower model()s? It seems to be an option according to development in fable and fabletools... but I can't turn it on. Can someone please tell me what I am missing? Sys.setenv(TZ =…
seapen
  • 345
  • 1
  • 4
  • 13
2
votes
1 answer

R R6 Inheritance with roxygen2 - class "ParentClass" is not exported by 'namespace:ParentPackage'

I am running into an issue with R6 inheritance. I am writing 2 packages (work related so I have to use fake code but I'll try to keep it accurate). In ParentPackage, I define an R6 class ParentClass. #' @name ParentClass #' @title ParentClass…
gabagool
  • 640
  • 1
  • 7
  • 18
2
votes
1 answer

R shinyapp: renderUI does not work with nested modules R6 classes

I have a big shiny app with modules and I am converting some of these in R6 classes. All works well except for nested modules: I am facing an issue with namespaces and the uiOutput does not work. Here is a reproductible example. The class ClassTest…
2
votes
1 answer

How do document an S3 generic for an R6 class?

I have an R6 class myclass, and I have defined the S3 generic as.matrix for it. Everything works, but I'm getting 2 notes when I run R CMD check: Note 1: S3 methods shown with full name in documentation object 'as.matrix.myclass': …
Kyle Ward
  • 889
  • 1
  • 8
  • 18
2
votes
1 answer

how to dispatch summary() method in R6 object

I am using R6 to build an object which fields includes a data frame and other informations. I defined a first method $print() which I can call as obj1$print() or print(obj1) and both ways works just fine. > obj1$print() test object name: AA >…
frenkg
  • 23
  • 4