Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using validate within another package #146

Open
DJJ88 opened this issue Jul 3, 2021 · 1 comment
Open

Using validate within another package #146

DJJ88 opened this issue Jul 3, 2021 · 1 comment
Labels

Comments

@DJJ88
Copy link

DJJ88 commented Jul 3, 2021

Hello,

Many thanks for the validate package, I want to use validate within another package to hide
customized rule function from the global environment.

##' @export test
##' @import validate
##' @importFrom methods new
test  <- setRefClass("test",
                     field=list(dt ='data.frame'))

test$methods(
  initialize = function(x){
    dt <<- x
  },
  validate = function(){

    rules <-   validator(y_n = is.yes_no(a))
    summary(confront(.self$dt,rules))
  })


is.yes_no <- function(x){
  tolower(x) %vin% c("yes","no")
}

A minimal script would be

library(test)
df <- data.frame(a =rep(c("yes","NO",NA),4))
obj <- test(df)
obj$validate()

### >
   name items passes fails nNA error warning   expression
1  y_n     0      0     0   0  TRUE   FALSE is.yes_no(a)

and generates an error because is.yes_no is not is scope.

However the configuration where is.yes_no is exported works fine but I'd like to hide it.

##' @export 
is.yes_no <- function(x){
  tolower(x) %vin% c("yes","no")
}

Question: Is it possible to give confront access to is.yes_no without exporting it?

@markvanderloo
Copy link
Member

In part, this is related to #45, where we wish to make it possible for users to register their own validation functions, so you do not need to prepend the function with "is.".

I'm a bit surprised that is.yes_no is not found. That is something I should look into a bit further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants