Open josmos opened 1 year ago
Hi There, for any function f(...)
that returns a logical vector you can create a rule like this
rules <- validator( f(x,z) == TRUE)
if you need to compare, say variables x and y to z, than you could use a variable group like so:
rules <- validator(
G := var_group(x,y)
, f(G,z)
)
The other option is to generate the rules in a file and read them later.
template <- "f(%s,z)"
txt <- paste(sprintf(template, some_vector_of_names), collapse="\n")
write(txt, file="rules.R")
rules <- validator(.file="rules.R")
I have a similar issue, in a previous version I was able to use the inline function A %==% B within rules, this seems to no longer be the case. Do I have to rewrite all rules that used this function to something like eq(A,B) == TRUE?
`%==%`<- function(e1,e2){
if(length(e1) == length(e2)){
isEqual <- e1 == e2 | (is.na(e1)) & (is.na(e2))
isEqual[is.na(isEqual)] <- FALSE
return(isEqual)
}
else{
return(FALSE)
}
Thanks
I have a rather complex function comparing (possibly partial) date strings:
I have a lot of date-columns to compare. Making rules with simple expressions for each column combination would be a mess. Is it possible to make this comparison with validate using a function like this (or similar one)? How could this be implemented?