OpasnetUtils/Init.assessment: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
 
(5 intermediate revisions by one other user not shown)
Line 1: Line 1:
[[Category:Opasnet]]
[[Category:Opasnet]]
[[Category:R tools]]
[[Category:R tools]]
[[Category:OpasnetUtils]]
{{method|moderator=|stub=Yes}}
{{method|moderator=|stub=Yes}}


Line 9: Line 10:


==Parameters==
==Parameters==
====Dependencies====
====Dependencies====
* A data.frame that has the structure of oassessment@name (Columns: Name, Identifier, Direction, Result)
* A data.frame that has the structure of oassessment@name (Columns: Name, Identifier, Direction, Result)


==Code==
==Code==
<rcode
name="answer"
label="Initiate functions"
graphics="1"
>
library(OpasnetBaseUtils)
library(xtable)
n <- 5
# INIT.ASSESSMENT ########## init.assessment 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)
init.assessment <- function(dependencies)
{
dependencies  <- fetch(dependencies)
decisions    <- fetch(dependencies[dependencies$Result == "decisions", "Identifier"])
stakeholders  <- fetch(dependencies[dependencies$Result == "stakeholders", "Identifier"])
probabilities <- fetch(dependencies[dependencies$Result == "probabilities", "Identifier"])
dependencies  <- dependencies[!dependencies$Result %in% c("decisions", "stakeholders", "probabilities"), ]
vars          <- list()
for(x 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[x]), ".\n", sep = "")
ident <- as.character(dependencies$Identifier[x])
temp <- tidy(op_baseGetData("opasnet_base", ident), direction = as.character(dependencies$Direction[x]))
temp <- make.ovariable(temp)
if(exists(paste("formula.", ident, sep = "")))
{temp@formula <- get(paste("formula.", ident, sep = ""))}
if(exists(paste("dependencies.", ident, sep = "")))
{temp@dependencies <- get(paste("dependencies.", ident, sep = ""))}
vars[as.character(dependencies$Result[x])] <- temp
}
assessment <- new("oassessment",
dependencies  = dependencies,
decisions    = decisions,
stakeholders  = stakeholders,
probabilities = probabilities,
vars          = vars
)
return(assessment)
# Does it cause problems to use the wide direction? Anyway, there should be exactly one Result column.
## No it doesn't if the Observation columns are such as Unit, Result, Description.
}


</rcode>
https://www.opasnet.org/svn/opasnet_utils/trunk/R/InitAssessment.r


==See also==
==See also==
Line 66: Line 23:
* [[Object-oriented programming in Opasnet]]
* [[Object-oriented programming in Opasnet]]
* [[Opasnet (R library)]]
* [[Opasnet (R library)]]
* [[Decision]]

Latest revision as of 13:36, 16 August 2012



Description

init.assessment 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)

Code

https://www.opasnet.org/svn/opasnet_utils/trunk/R/InitAssessment.r

See also