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

Use cli package in read_ functions #181

Merged
merged 18 commits into from
Mar 19, 2024
Merged

Use cli package in read_ functions #181

merged 18 commits into from
Mar 19, 2024

Conversation

peterdesmet
Copy link
Member

This PR completes #163.

  • cli calls are used in read_ functions.
  • Some messages were updated for consistency and new cli capabilities.
  • Each error, message, warning is tested for both class and the actual text that is returned.
  • In tests, I did not use rlang::local_options() but kept the suppressMessages(), as advised in testthat.
  • glue and assertthat dependencies are removed.
  • Some complexity regarding a col_names variable is removed from read_resource().
  • When reading a datapackage.json, it is no longer required that all resources have a name 0c7b752. When reading a resource, it still is.
  • Update NEWS.md (it references the rOpenSci verbosity blog post).

…require a name

The previous assertion checked for:

1. Resources property missing
2. Resources property = empty list
3. Resources do not have a name

That last assertion is removed, so it is now possible to read a package where not all the resources have a name. For any later step however, check_package() requires all resources to have a name. See class "frictionless_error_resources_without_name". I did not want to include this test in two places. Note also that name might not be required anymore in frictionless v2.

Ping @PietrH
It's a general feature of cli, which I don't consider necessary to document here.
Originally:

```
field_names <- purrr::map_chr(fields, ~ purrr::pluck(.x, "name"))
col_names <- purrr::map_chr(fields, ~ replace_null(.x$name, NA_character_))
```

Both are derived from fields, but col_names had an (untested) assert that the fields were not NA. That "frictionless_error_fields_without_name" test however is already part of check_schema(), which is called in get_schema(), which is called in read_resource(), so fields without name will never be passed.

Since col_names is the same as field_names in the function, we should only have one variable.
Ping @PietrH: This change is a good example of how nicely cli takes care of collapsing, pluralization, etc.
@peterdesmet peterdesmet requested a review from PietrH March 15, 2024 12:30
@peterdesmet peterdesmet linked an issue Mar 15, 2024 that may be closed by this pull request
35 tasks
I notice in other packages (and style guides) that NEWS.md is hard-wrapped at 80 chars and has lots of spacing between bullet items. I find this annoying:

- It renders ok (wrapping and spacing is ignored) on GitHub and pkgdown website.
- But the text is also often copy/pasted for GitHub and Zenodo releases, where the hard-wrapping is not ignored.

In addition, this is a pure Markdown file, I rather use the Markdown conventions over the R conventions.
Copy link
Contributor

@damianooldoni damianooldoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! A pair of wrong links but the rest seems ok to me.

NEWS.md Outdated Show resolved Hide resolved
NEWS.md Outdated Show resolved Hide resolved
@peterdesmet peterdesmet merged commit 35eeeef into main Mar 19, 2024
8 checks passed
@peterdesmet peterdesmet deleted the cli_read branch March 19, 2024 18:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use cli package for warnings and messages, drop assertthat
2 participants