wahani / modules

Modules in R
https://cran.r-project.org/package=modules
Other
81 stars 3 forks source link

Possibility to assert methods/typecheck #8

Closed jenzopr closed 6 years ago

jenzopr commented 6 years ago

Hi!

I wonder if it possible to assert if a module exports a function and/or variable with a certain name?

E.g. I would like to do:

m <- module({
  type <- 'action'
  boringFunction <- function() "boring output"
})
> has_function(m, "boringFunction")
> [1] True

Best and thank you for a quick hint! Jens

wahani commented 6 years ago

I am not sure I understand exactly what you need:

Is type important for you example? Is the following useful for you?

m <- modules::module({
  boringFunction <- function() "boring output"
})

hasFunction <- function(m, name) {
  exists(name, m, mode = "function")
}

hasFunction(m, "boringFunction")
hasFunction(m, "foo")
jenzopr commented 6 years ago

I needed the checks on the interface, correct!

Thanks a lot!

wahani commented 6 years ago

You're welcome.

-s