Assuming that the class and instantiation of class are held in 2 separate files, how would you import the class data prior to instantiate the class?
Below code works fine if held in one same file, but I suspect that as soon as the code base starts growing you would want to split the data into smaller code chunks.
Should I use [source], does it exist an autoloader or any another guideline?
File: _class_data.R
if (!"package:R6" %in% search()) {
library(R6)
}
# Class 1
Class_1 <- R6Class("Class_1",
public = list(
# Properties:
x = 0,
# Lists:
credentials = list(
user = "user",
password = "pass"
),
# Functions:
myFunction = function() {
return(self$x)
}
)
)
File: run.R
# Should I add a [source] path here to [ _class_data.R] ?
# Instantiate a class by creating an object.
class_1 <- Class_1$new()