R/evaluation-functions.R
65260a4d
 #############################
 #       EVALUATION         #
 ############################
 
 #' Condition evaluation functions
 #'
f345b6e2
 #' This function is used to support joinBy and/or groupBy function parameter.
65260a4d
 #'
f345b6e2
 #' @param default concatenation of string identifying a name of metadata 
 #' attribute to be evaluated. 
 #' It defines a DEFAULT evaluation of the input values. 
c93d8511
 #' DEFAULT evaluation: the two attributes match if both end with value.
 #' 
f345b6e2
 #' @param full concatenation of string identifying a name of metadata 
 #' attribute to be evaluated.
c93d8511
 #' It defines a FULL (FULLNAME) evaluation of the input values.
65260a4d
 #' FULL evaluation: two attributes match if they both end with value and,
c93d8511
 #' if they have further prefixes, the two prefix sequences are identical.
 #' 
f345b6e2
 #' @param exact concatenation of string identifying a name of metadata 
 #' attribute to be evaluated.
c93d8511
 #' It defines a EXACT evaluation of the input values.
83eb0624
 #' EXACT evaluation: only attributes exactly as value match; 
c93d8511
 #' no further prefixes are allowed. 
65260a4d
 #' 
f345b6e2
 #' @return list of 2-D array containing method of evaluation and metadata 
 #' attribute name
65260a4d
 #' 
 #' 
e5131ba8
 #' @name Evaluation-Function
c93d8511
 #' @aliases condition_evaluation
65260a4d
 #' @rdname condition_eval_func
 #' @export
4ad24353
 conds <- function(default = c(""), full = c(""), exact = c("")) {
c9b073a5
   df <- .condition("DEF",default)
   fn <- .condition("FULL",full)
   ex <- .condition("EXACT",exact)
   list("condition" = list("def" = df, "full" = fn, "exact" = ex))
65260a4d
 }
 
4ad24353
 .condition <- function(cond, array) {
c9b073a5
   array = array[!array %in% ""]
   array = array[!duplicated(array)]
   
73652f4d
   if(!length(array)) {
c9b073a5
     join_condition_matrix <- NULL
73652f4d
   } else {
c9b073a5
     join_condition_matrix <- t(vapply(array, function(x) {
       new_value = c(cond, x)
       matrix <- matrix(new_value)
     },character(2)))
   }
   join_condition_matrix
65260a4d
 }