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

Property validation #275

Closed
kkmann opened this issue Feb 12, 2023 · 3 comments · Fixed by #339
Closed

Property validation #275

kkmann opened this issue Feb 12, 2023 · 3 comments · Fixed by #339
Labels
discuss 🗣 feature a feature request or enhancement

Comments

@kkmann
Copy link

kkmann commented Feb 12, 2023

Dear all,

I was wondering whether it would be feasible to add optional constraints to property definitions like

myclass <- new_class("myclass", properties = list(
  a = class_double(min = 0, na_ok = FALSE)
))

Ideally, this would then also be picked up by roxygen2 when documenting class properites. Might be out of scope of a OOP system, but would be kind of handy to have...

Alternatively, do you see a way of standardizing input checking like this in the validator to autogenerate documentation of the constraints?

@lawremi
Copy link
Collaborator

lawremi commented Feb 13, 2023

There could be convenience functions for constructing properties with constraints like this. There's precedent for this sort of thing in property implementations from other languages.

@hadley hadley added the feature a feature request or enhancement label Apr 10, 2023
@hadley
Copy link
Member

hadley commented Apr 17, 2023

We'd also need to add the idea of a property validator, but I think that makes sense.

Would be worth considering whether we want to provide canned property classes that represent scalars (but that's a fairly big design problem, so might be worth leaving that to a package).

@hadley hadley changed the title Property constraints Property validation Apr 17, 2023
@jl5000
Copy link

jl5000 commented Apr 21, 2023

In my own use of S7 I would certainly find this very useful. I have implemented a set of validator functions dependent on the type of property:

  • Min/max length of atomic vectors/lists
  • Min/max character length of strings
  • Min/max values of numerics
  • Ensuring character properties fit regex patterns
  • Ensuring character properties take one of a number of set values
  • Ensuring lists contain elements of acceptable classes

Incorporating any of these into S7 would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discuss 🗣 feature a feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants