Refactor `read_resource()`
This PR fixes #210 by refactoring read_resource(). It uses several helper functions placed in utils.R.
The PR adds the helper functions here below. Comments describe the differences between the description of @peterdesmet in #210 and the actual implementation:
-
get_encoding(). Used increate_local()(see below) -
create_locale(). It needsresource$encodingandresource$fields. I didn't passresource(andpackage) as I didn't see the advantage. It doesn't decrease the number of arguments and it makes the helper functionget_encoding()longer: we need to callget_schema()in the function again. -
create_col_types()(wrapper) andcreate_col_type()instead of the proposedget_cols()andget_col(). I find the verbgetin the function name a little misleading: the functions are creating col types for the resource to read, not getting them from the resource. -
col_integer(),col_number(),col_string(),col_date(),col_time(),col_datetime(), used inswitch()increate_col_type(). It follows the specs in #210. - ~
read_from_paths()(wrapper) and~read_from_path(): using amap_df()simplify extremely the code.
We could eventually move the helper functions created in this PR in an apart utility file, maybe utils-resource.R.
No addition to NEWS.md as it doesn't affect the user experience. But we could add it if wished.
Some errors while checking: convert to draft.
Please create:
-
get_encoding.R -
create_locale.R -
create_col_types.R -
col_types.R -
read_from_path.R
Codecov Report
All modified and coverable lines are covered by tests :white_check_mark:
Project coverage is 100.00%. Comparing base (
940aa7f) to head (324d49d).
Additional details and impacted files
@@ Coverage Diff @@
## main #244 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 18 22 +4
Lines 597 626 +29
=========================================
+ Hits 597 626 +29
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.
Well done, @peterdesmet!