I am attempting to change the value of a property, throughout the course of running an instantiated object. This is part of a download mechanism where value 20 is set to perform a first download of data for 20 lines, the rest of downloads will be set to 1 line. It is written in R object-oriented programming, using package R6.
The value is remembered because it is stored in the object (previously instantiated from class).
Script is being triggered from Rstudio (version: 1.1.456).
Observation:
The script do switch the property value from NULL
to 20
, in the first run.
Problem:
The value stays at 20
during all the script runs.
Wanted behaviour:
The first run, the value should start with NULL
and swap to 20
.
The second run of script, the property value should start being 20
thus react on the if-statement and change value to 1
.
From 3rd run, and all rest of runs the value should star being 1
and the if-statement will not find any matching, keeping the value to 1
.
# ----------------------------------------
# Classes.
# ----------------------------------------
Download <- R6Class("Download",
public = list(
# --------------------------------------------
# Initializer:
# --------------------------------------------
initialize = function(value = NULL) {
self$value <- value
},
# --------------------------------------------
# Properties:
# --------------------------------------------
value = NULL,
# --------------------------------------------
# Functions:
# --------------------------------------------
run = function() {
self$value_switcher()
},
value_switcher = function() {
if(is.null(self$value)) {
self$value = 20
} else if(self$value == 20) {
self$value = 1
}
cat("Your property value is :", self$value)
}
) # Closure of list.
) # Closure of class.
download <- Download$new() # Instantiate the class.
download$run() # Run object methods.