Difference between revisions of "OpasnetUtils/Ovariable"

From Testiwiki
Jump to: navigation, search
m
(code replaced with link to code)
 
(3 intermediate revisions by one other user not shown)
Line 4: Line 4:
 
{{method|moderator=|stub=Yes}}
 
{{method|moderator=|stub=Yes}}
  
=movariable=
+
== Definition ==
==Description==
 
movariable takes a data.frame, a function, and a list and makes an ovariable out of them. It is a subfunction of [[make.ovariable]] and prevents infinite recursion of S4 methods.
 
  
==Code==
+
=== Description ===
<rcode
+
Defines the S4 class "ovariable" which is the basic building block in open assessments
name="movariable"
 
label="Initiate functions"
 
graphics="1"
 
>
 
# MOVARIABLE ########## movariable takes a data.frame, a function, and a list and makes an ovariable out of them. It is a
 
#####subfunction of make.ovariable and prevents infinite recursion of S4 methods.
 
movariable <- function(
 
data,
 
formula,
 
dependencies,
 
name
 
) {
 
output <- interpret(data)
 
out <- new("ovariable",
 
name        = name,
 
output      = output,
 
data        = data,
 
marginal    = ifelse(colnames(output) %in% c("Result", "Unit"), FALSE, TRUE),
 
formula      = formula,
 
dependencies = dependencies
 
)
 
out <- update(out)
 
return(out)
 
}
 
  
</rcode>
+
=== Code ===
  
 
+
https://www.opasnet.org/svn/opasnet_utils/trunk/R/OVariable.r
 
 
=setclass.ovariable=
 
==Description==
 
Defines the S4 class "ovariable" which is the basic building block in open assessments.
 
 
 
==Code==
 
<rcode
 
name="setclass.ovariable"
 
label="Initiate functions"
 
graphics="1"
 
>
 
# SETCLASS OVARIABLE ################### Defines the S4 class "ovariable" which is the basic building block in open assessments.
 
temp <- setClass(
 
"ovariable",
 
representation(
 
name        = "character",
 
output      = "data.frame",
 
data        = "data.frame",
 
marginal    = "vector",
 
formula      = "function",
 
dependencies = "data.frame"
 
)
 
)
 
</rcode>
 
 
 
 
 
 
 
=setmethod.make.ovariable=
 
==Description==
 
make.ovariable takes a vector or data.frame and makes an ovariable out of it.
 
 
 
==Code==
 
<rcode
 
name="make.ovariable"
 
label="Initiate functions"
 
graphics="1"
 
>
 
# SETMETHOD MAKE.OVARIABLE ################################################################################
 
########### make.ovariable takes a vector or data.frame and makes an ovariable out of it.
 
make.ovariable <- function(
 
data,
 
formula = function(dependencies){return(0)},
 
dependencies = list(x = 0),
 
name = ""
 
) {
 
return(movariable(data, formula, dependencies, name))
 
}
 
 
 
temp <- setGeneric("make.ovariable") # Makes make.ovariable a generic S4 function.
 
 
 
temp <- setMethod(
 
f = "make.ovariable",
 
signature = signature(data = "data.frame"),
 
definition = function(
 
data,
 
formula = function(dependencies){return(0)},
 
dependencies = data.frame(),
 
name = ""
 
) {
 
cat("Data frame\n")
 
return(movariable(data, formula, dependencies, name))
 
}
 
)
 
 
 
temp <- setMethod(
 
f = "make.ovariable",
 
signature = signature(data = "vector"),
 
definition = function(
 
data,
 
formula = function(dependencies){return(0)},
 
dependencies = data.frame(),
 
name = ""
 
) {
 
cat("Vector\n")
 
data <- data.frame(Result = data)
 
return(make.ovariable(data, formula, dependencies, name))
 
}
 
)
 
 
 
temp <- setMethod(
 
f = "make.ovariable",
 
signature = signature(data = "list"),
 
definition = function(
 
data,
 
formula = function(dependencies){return(0)},
 
dependencies = data.frame()
 
) {
 
for(i in 1:length(data)) {
 
cat("List", i, "\n")
 
data[[i]] <- make.ovariable(data[[i]], formula, dependencies, name = names(data)[[i]])
 
}
 
return(data)
 
}
 
)
 
 
 
temp <- setMethod(
 
f = "make.ovariable",
 
signature = signature(data = "ovariable"),
 
definition = function(
 
data,
 
formula = NULL,
 
dependencies = NULL,
 
name = NULL
 
) {
 
cat("ovariable\n")
 
if(is.null(formula))      {formula      <- data@formula}
 
if(is.null(dependencies)) {dependencies <- data@dependencies}
 
if(is.null(formula))      {name        <- data@name}
 
return(movariable(data@data, formula, dependencies, name))
 
}
 
)
 
</rcode>
 
  
 
==See also==
 
==See also==

Latest revision as of 13:57, 16 August 2012



Definition

Description

Defines the S4 class "ovariable" which is the basic building block in open assessments

Code

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

See also