-
Notifications
You must be signed in to change notification settings - Fork 11
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
Should we use resource
as an argument?
#251
Comments
Thanks @peterdesmet for the nice summary. Here below my two cents
|
For a while I've been thinking about an approach close to this, but where resources are loaded by But I guess here we're talking about just resource descriptors, without their data loaded. Still, I think a resource class would be an interesting approach -- this class could be upgraded to the subclassed tibble when the user decided to load data (but then after loading data the object would still work with all the original descriptor fns)
The nice thing about making the resource descriptor its own class, is that you wouldn't need to always be scanning the descriptor to see if it was valid if you only allowed valid resources to be stamped with the custom class. (So the class operates in a sort of This would mean that you would not want to allow resource descriptors to be mutated directly; instead you'd provide an API that would allow the user to add / remove descriptor properties but always verify they resulted in a valid descriptor. (Similar to what I suggest in #198) I'll see about pulling together an example to demonstrate more of what I mean... |
The following helper functions have
package
andresource_name
as arguments:locale()
read_from_path()
write_resource()
But they are called from functions that already have the
resource
. That means that currently, they recallget_resource()
, in the case forlocale()
for a third time:read_resource()
->read_from_path()
->locale()
This could be simplified by passing
resource
as an argumentlocale()
: needsresource$encoding
andfields
. Callsget_schema()
read_from_path()
: needsresource$dialect
,schema
andfield_names
. Callsget_schema()
write_resource()
: needsresource
get_schema()
needspackage$directory
The problem with
get_schema()
is that is needspackage$directory
, so merely passing the resource is not enough. Solutions:directory
argument toget_schema()
: no, this is clunkydirectory
toresource
as part ofget_resource()
. That way,get_schema()
can get it from there. It can be removed as part ofwrite_resource()
Using
resource
forget_schema()
If the helper functions use
resource
as an argument, one could argue to also use it for the public functionget_schema(resource)
. If we do that,get_resource()
should become a public function too, which can be useful (especially for developers). The downside is that (public) functions that useresource
should then check if it is valid. Most of theget_resource()
checks should then move to acheck_resource()
function.@damianooldoni @khusmann others... Thoughts?
The text was updated successfully, but these errors were encountered: