Skip to content

Commit

Permalink
Proper handling of environments in R6 classes
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwarkentin committed Jan 17, 2024
1 parent 80ddc59 commit d63e1a2
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
10 changes: 6 additions & 4 deletions R/R6ClassModelRun.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ OpenMppModelRun <-
#' @field RunMetadata Run metadata.
RunMetadata = NULL,

#' @field Parameters Run parameters.
Parameters = rlang::env(),
#' @field Parameters Model run parameters.
Parameters = NULL,

#' @field Tables Run tables
Tables = rlang::env(),
#' @field Tables Model run output tables
Tables = NULL,

#' @field OpenMppType OpenM++ object type (used for `print()`).
OpenMppType = 'ModelRun',
Expand Down Expand Up @@ -159,6 +159,7 @@ OpenMppModelRun <-
private$.tables <- total
},
.load_table_bindings = function() {
self$Tables <- rlang::env()
purrr::walk(private$.run$Table, \(table) {
private$.add_table(table$Name)
f <- function() {
Expand All @@ -169,6 +170,7 @@ OpenMppModelRun <-
})
},
.load_run_param_bindings = function() {
self$Parameters <- rlang::env()
purrr::walk(private$.run$Param, \(param) {
f <- function() {
param_name <- param$Name
Expand Down
5 changes: 3 additions & 2 deletions R/R6ClassModelRunSet.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ OpenMppModelRunSet <-
#' @field OpenMppType OpenM++ object type (used for `print()`).
OpenMppType = 'ModelRunSet',

#' @field Tables Run tables
Tables = rlang::env(),
#' @field Tables Model run output tables
Tables = NULL,

#' @description
#' Create a new OpenMppModelRunSet object.
Expand Down Expand Up @@ -130,6 +130,7 @@ OpenMppModelRunSet <-
private$.tables <- total
},
.load_table_bindings = function() {
self$Tables <- rlang::env()
purrr::walk(private$.runs[[1]]$private$.run$Table, \(table) {
private$.add_table(table$Name)
f <- function() {
Expand Down
3 changes: 2 additions & 1 deletion R/R6ClassWorkset.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ OpenMppWorkset <-
OpenMppType = 'Workset',

#' @field Parameters Workset parameters.
Parameters = rlang::env(),
Parameters = NULL,

#' @description
#' Create a new OpenMppWorkset object.
Expand Down Expand Up @@ -284,6 +284,7 @@ OpenMppWorkset <-
},
.load_param_bindings = function() {
private$.params <- NULL
self$Parameters <- rlang::env()
purrr::walk(private$.workset$Param, \(param) {
private$.add_params(param$Name)
f <- function(data) {
Expand Down
4 changes: 2 additions & 2 deletions man/load_model_run.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/load_model_runs.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit d63e1a2

Please sign in to comment.