Skip to content

Commit

Permalink
Merge pull request #208 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
merge from main
  • Loading branch information
dannyparsons committed Jun 7, 2016
2 parents 1da8de7 + 1e57c67 commit 220aebf
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions instat/static/InstatObject/R/instat_object_R6.R
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,29 @@ instat_object$set("public", "reorder_objects", function(data_name, new_order) {
}
)

instat_object$set("public", "get_from_object", function(data_name, object_name, value1, value2, value3) {
if(missing(data_name) || missing(object_name)) stop("data_name and object_name must both be specified.")
curr_object = self$get_objects(data_name = data_name, object_name = object_name)
if(missing(value1)) {
if(!missing(value2) || !missing(value3)) warning("value1 is missing so value2 and value3 will be ignored.")
return(curr_object[])
}
if(!value1 %in% names(curr_object)) stop(value1, " not found in ", object_name)
if(missing(value2)) {
if(!missing(value3)) warning("value2 is missing so value3 will be ignored.")
return(curr_object[[value1]])
}
else {
if(!value2 %in% names(curr_object[[value1]])) stop(paste0(value2, " not found in ", object_name,"[[\"",value1,"\"]]"))
if(missing(value3)) return(curr_object[[value1]][[value2]])
else {
if(!value3 %in% names(curr_object[[value1]][[value2]])) stop(paste0(value3, " not found in ", object_name,"[[\"",value1,"\"]]","[[\"",value2,"\"]]"))
return(curr_object[[value1]][[value2]][[value3]])
}
}
}
)

instat_object$set("public", "add_model", function(data_name, model, model_name) {
self$add_object(data_name = data_name, object = model, object_name = model_name)
}
Expand All @@ -507,22 +530,7 @@ instat_object$set("public", "get_model_names", function(data_name, include_overa
)

instat_object$set("public", "get_from_model", function(data_name, model_name, value1, value2, value3) {
if(missing(data_name) || missing(model_name)) stop("data_name and model_name must both be specified.")
curr_model = self$get_models(data_name = data_name, model_name = model_name)
if(missing(value1)) stop("value1 must be specified.")
if(!value1 %in% names(curr_model)) stop(paste(value1, "not found in", model_name))
if(missing(value2)) {
if(!missing(value3)) warning(paste("value2 is missing so value3 =",value3, "will be ignored."))
return(curr_model[[value1]])
}
else {
if(!value2 %in% names(curr_model[[value1]])) stop(paste0(value2, " not found in ", model_name,"[[\"",value1,"\"]]"))
if(missing(value3)) return(curr_model[[value1]][[value2]])
else {
if(!value3 %in% names(curr_model[[value1]][[value2]])) stop(paste0(value3, " not found in ", model_name,"[[\"",value1,"\"]]","[[\"",value2,"\"]]"))
return(curr_model[[value1]][[value2]][[value3]])
}
}
self$get_from_object(data_name = data_name, object_name = model_name, value1 = value1, value2 = value2, value3 = value3)
}
)

Expand Down

0 comments on commit 220aebf

Please sign in to comment.