From f1c22af6c88ef58322c5ae572b5b905fd8a64c19 Mon Sep 17 00:00:00 2001 From: Gavin Rhys Lloyd Date: Fri, 17 Nov 2023 10:22:00 +0000 Subject: [PATCH] return unique for inherited classes --- R/output_class.R | 36 ++++++++++++++++++------------------ R/parameter_class.R | 34 +++++++++++++++++----------------- 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/R/output_class.R b/R/output_class.R index 6f4647e..88df407 100644 --- a/R/output_class.R +++ b/R/output_class.R @@ -1,6 +1,6 @@ #' @include generics.R struct_class.R -#' -#' @describeIn output_obj +#' +#' @describeIn output_obj #' @export setMethod(f = "output_obj", signature = c("struct_class","character"), @@ -10,7 +10,7 @@ setMethod(f = "output_obj", } ) -#' @describeIn output_obj +#' @describeIn output_obj #' @export #' @return the modified object setMethod(f = "output_obj<-", @@ -24,21 +24,21 @@ setMethod(f = "output_obj<-", } ) -#' @describeIn is_output +#' @describeIn is_output #' @export setMethod(f = "is_output", signature = c("struct_class"), definition = function(obj,name) { - + # include params set for parent objects valid = output_ids(obj) - + # if valid param_id then return true return(name %in% valid) } ) -#' @describeIn output_ids +#' @describeIn output_ids #' @export setMethod(f = "output_ids", signature = c("struct_class"), @@ -46,23 +46,23 @@ setMethod(f = "output_ids", # include params set for parent objects parents = is(obj) w=which(parents == 'struct_class') - + valid=NULL for (k in 1:w) { - + # skip stato if (parents[k]=='stato') { next } - + valid = c(valid,new_struct(parents[k])@.outputs) } - - return(valid) + + return(unique(valid)) } ) -#' @describeIn output_name +#' @describeIn output_name #' @export setMethod(f = "output_name", signature = c("struct_class",'character'), @@ -79,7 +79,7 @@ setMethod(f = "output_name", } ) -#' @describeIn output_list +#' @describeIn output_list #' @export setMethod(f = 'output_list', signature = c('struct_class'), @@ -93,7 +93,7 @@ setMethod(f = 'output_list', } ) -#' @describeIn output_list +#' @describeIn output_list #' @export setMethod(f = 'output_list<-', signature = c('struct_class','list'), @@ -106,12 +106,12 @@ setMethod(f = 'output_list<-', } ) -#' @describeIn output_value +#' @describeIn output_value #' @export setMethod(f = "output_value", signature = c("struct_class","character"), definition = function(obj,name) { - + p = slot(obj, name) # if the output is an entity then set its value if (is(p,'entity')) { @@ -125,7 +125,7 @@ setMethod(f = "output_value", ) -#' @describeIn output_value +#' @describeIn output_value #' @export setMethod(f = "output_value<-", signature = c("struct_class","character"), diff --git a/R/parameter_class.R b/R/parameter_class.R index 96b005d..38a4c8a 100644 --- a/R/parameter_class.R +++ b/R/parameter_class.R @@ -14,7 +14,7 @@ setMethod(f = "param_obj<-", ) #' @export -#' @rdname param_obj +#' @rdname param_obj setMethod(f = "param_obj", signature = c("struct_class","character"), definition = function(obj,name) { @@ -25,11 +25,11 @@ setMethod(f = "param_obj", #' @export -#' @describeIn is_param +#' @describeIn is_param setMethod(f = "is_param", signature = c("struct_class"), definition = function(obj,name) { - + # include params set for parent objects valid = param_ids(obj) @@ -39,33 +39,33 @@ setMethod(f = "is_param", ) #' @export -#' @describeIn param_ids +#' @describeIn param_ids setMethod(f = "param_ids", signature = c("struct_class"), definition = function(obj) { - + # include params set for parent objects parents = is(obj) w=which(parents == 'struct_class') - + valid=NULL for (k in 1:w) { - + # skip stato if (parents[k]=='stato') { next } - + valid = c(valid,new_struct(parents[k])@.params) } - - return(valid) + + return(unique(valid)) } ) #' @export -#' @describeIn param_name +#' @describeIn param_name setMethod(f = "param_name", signature = c("struct_class",'character'), definition = function(obj,name) { @@ -75,14 +75,14 @@ setMethod(f = "param_name", value = p$name return(value) } - + # otherwise just return the slot name return(name) } ) #' @export -#' @describeIn param_list +#' @describeIn param_list setMethod(f = 'param_list', signature = c('struct_class'), definition = function(obj) { @@ -96,7 +96,7 @@ setMethod(f = 'param_list', ) #' @export -#' @describeIn param_list +#' @describeIn param_list setMethod(f = 'param_list<-', signature = c('struct_class','list'), definition = function(obj,value) { @@ -109,12 +109,12 @@ setMethod(f = 'param_list<-', ) #' @export -#' @describeIn param_value +#' @describeIn param_value setMethod(f = "param_value", signature = c("struct_class","character"), definition = function(obj,name) { p = slot(obj, name) - + # if the parameter is an entity then set its entity value if (is(p,'entity')) { value = value(p) @@ -128,7 +128,7 @@ setMethod(f = "param_value", ) #' @export -#' @describeIn param_value +#' @describeIn param_value setMethod(f = "param_value<-", signature = c("struct_class","character","ANY"), definition = function(obj,name,value) {