Make.oassessment: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
(redirected)
 
(3 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:Opasnet]]
#REDIRECT [[OpasnetUtils]]
[[Category:R tools]]
[[Category:OpasnetUtils]]
{{method|moderator=|stub=Yes}}
 
==Description==
make.oassessment creates S4 assessment from dependencies data.frame, including decisions, stakeholders, probabilities, and variables.
 
<b>NOTE! You must include the formula code from each variable page, otherwise formulas and dependencies are not updated. </b>
 
==Parameters==
====Dependencies====
* a data.frame that has the structure of oassessment@name (Columns: Name, Identifier, Direction, Result)
 
==Code==
<rcode
name="answer"
label="Initiate functions"
graphics="1"
>
# MAKE.OASSESSMENT ########## make.oassessment creates S4 assessment from dependencies data.frame, including decisions, stakeholders, probabilities, and variables.
########### NOTE! You must include the formula code from each variable page, otherwise formulas and dependencies are not updated.
########### Parameters:
## dependencies: a data.frame that has the structure of oassessment@name (Columns: Name, Identifier, Direction, Result)
make.oassessment <- function(x) {
x  <- fetch(x)
decisions    <- fetch(x[x$Result == "decisions",    "Identifier"])
stakeholders  <- fetch(x[x$Result == "stakeholders",  "Identifier"])
probabilities <- fetch(x[x$Result == "probabilities", "Identifier"])
dependencies  <- x[!x$Result %in% c("decisions", "stakeholders", "probabilities"), ]
vars          <- list()
for(i in 1:nrow(dependencies)) { # Objects with names as aliases are created and filled with data from Opasnet Base.
cat("Initialising variable ", as.character(dependencies$Name[i]), ".\n", sep = "")
ident <- as.character(dependencies$Identifier[i])
data <- fetch(ident, direction = as.character(dependencies$Direction[i]))
if(exists(paste("formula.", ident, sep = "")))
{formula <- get(paste("formula.", ident, sep = ""))
} else {
formula <- function(dependencies) {return(0)}
}
if(exists(paste("dependencies.", ident, sep = "")))
{depend <- get(paste("dependencies.", ident, sep = ""))
} else {
depend <- data.frame()
}
vars[[i]] <- make.ovariable(
name = as.character(dependencies$Result[i]),
data = data,
formula = formula,
dependencies = depend
)
}
names(vars) <- dependencies$Result
assessment <- new("oassessment",
dependencies  = dependencies,
decisions    = decisions,
stakeholders  = stakeholders,
probabilities = probabilities,
vars          = vars
)
 
return(assessment)
}
 
</rcode>
 
==See also==
 
* [[OpasnetBaseUtils]]
* [[Object-oriented programming in Opasnet]]
* [[Opasnet (R library)]]

Latest revision as of 12:50, 20 August 2014

Redirect to: