You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Should defining a constructor really be "Advanced use only?" #245
This looks like a great project and I've been following it for a little while.
I did notice a few issues around constructors. First, the documentation claims that defining a constructor is for advanced use only. Should this be the case? Usually a constructor provides pre-processing steps to go from arguments to properties/attributes. This is not advanced usage in most other languages. Second, the documentation isn't sufficient to create a constructor in a class. I did try looking through the tests for an example but noted that the test in test-constructor.R file creates a class but fails when one tries to instantiate an instance.
It's advanced use only since you have to figure out how to build the constructor yourself 😛 (I'll definitely document that better). Maybe expert use only would be better phrasing? I don't think we expect many people to supply the constructor themselves. In the case where you wanted different arguments to properties, I'd think you'd create a wrapper function. Do you have an example of what you're thinking?
I agree that creating a wrapper function is an alternative. For example, the range object in the documentation could take the range of a vector of points and you could create create_range() function as:
The issue is then create_range() is not encapsulated by the range class. This isn't wrong but I might like to be able to create with range(vals) in addition to range(start, end).
Activity
hadley commentedon Jul 29, 2022
It's advanced use only since you have to figure out how to build the constructor yourself 😛 (I'll definitely document that better). Maybe expert use only would be better phrasing? I don't think we expect many people to supply the constructor themselves. In the case where you wanted different arguments to properties, I'd think you'd create a wrapper function. Do you have an example of what you're thinking?
kaneplusplus commentedon Aug 1, 2022
:-) Fair enough.
I agree that creating a wrapper function is an alternative. For example, the range object in the documentation could take the range of a vector of points and you could create
create_range()function as:The issue is then
create_range()is not encapsulated by therangeclass. This isn't wrong but I might like to be able to create withrange(vals)in addition torange(start, end).BTW, this is a great project.
hadley commentedon Aug 1, 2022
Ah yeah, that makes sense. I'll tweak the docs to reflect this.
Briefly discuss custom constructors
Reorganise vignettes (#295)