OpasnetUtils/Ops: Difference between revisions

From Opasnet
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 14: Line 14:
label="Initiate functions"
label="Initiate functions"
graphics="1"
graphics="1"
showcode="1"
>
>
# SETMETHOD OPS ######### Arithmetic operations of ovariables: first they are merged by index columns,
# SETMETHOD OPS ######### Arithmetic operations of ovariables: first they are merged by index columns,

Revision as of 10:51, 15 June 2012



Description

Arithmetic operations of ovariables: first they are merged by index columns, then the operation is performed for the Result.x and Result.y columns.

If one of the expressions is numeric, it is first transformed to ovariable.

Code

- Hide code

# SETMETHOD OPS ######### Arithmetic operations of ovariables: first they are merged by index columns,
### then the operation is performed for the Result.x and Result.y columns.
### If one of the expressions is numeric, it is first transformed to ovariable.
temp <- setMethod(
	f = "Ops", 
	signature = signature(e1 = "ovariable", e2 = "ovariable"), 
	definition = function(e1, e2) {
		out <- merge(e1, e2)@output
		colnames(out) <- gsub(".x", "", colnames(out))
		out$Result <- callGeneric(out$Result, out$Result.y)
		if(!is.null(out$Unit.y)) {out$Unit <- paste(out$Unit, "|(", out$Unit.y, ")", sep= "")}
		e1@output <- out[, !colnames(out) %in% c("Result.y", "Unit.y")]
		return(e1)
	}
)

temp <- setMethod(
	f = "Ops", 
	signature = signature(e1 = "ovariable", e2 = "numeric"), 
	definition = function(e1, e2) {
		e2 <- make.ovariable(e2)
		e1 <- callGeneric(e1, e2)
		return(e1)
	}
)

temp <- setMethod(
	f = "Ops", 
	signature = signature(e1 = "numeric", e2 = "ovariable"), 
	definition = function(e1, e2) {
		e1 <- make.ovariable(e1)
		e1 <- callGeneric(e2, e1)
		return(e1)
	}
)

See also