0

This question relates to the previous one: How to change public R6 class method from outside of the class?. (the solution to which is posted here: How to change public R6 class method from outside of the class?) In that question, i needed to modify a class function from outside of class definition - as a code. In this question below, I need to modify it - given the test string

Specifically, I need a user to be able define a Data Transformation function self$fLTR for the R6 Class that processes data (e.g. via Shiny App).

Here's the class and example of desired result:

Simple <- R6Class(  "Simple",
  public = list(
    dt = NULL,
    fLTE = NULL
  )
)
s <- Simple$new()
s$dt <- mtcars
input$strLTEFunctionCode <- "function(self) { self$dt$cyl <- self$dt$cyl * 2 }"
s$lte <- as.function (input$strLTEFunctionCode)

Is that possible?

This would be very handy for OOP mentality - to include everything you need to know about your Object (Class) - including instruction on how to preprocess data (ie. the fLTE() function) as part of the Object (Class).

IVIM
  • 2,167
  • 1
  • 15
  • 41
  • Perhaps this post could help : https://stackoverflow.com/questions/26331030/dynamically-add-function-to-r6-class-instance – IVIM Mar 01 '23 at 16:56

0 Answers0