Skip to content

use bslib to load brand.yml files #241

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

Merged
merged 3 commits into from
May 19, 2025

Conversation

gordonwoodhull
Copy link
Contributor

@gordonwoodhull gordonwoodhull commented May 14, 2025

Use bslib to load brand.yml, so that brand palette colors are resolved, etc.

It would be even better to read the light and dark brands from the Quarto document's metadata, but we don't support that yet.

Copy link
Collaborator

@cderv cderv left a comment

Choose a reason for hiding this comment

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

Great !

I hope there will be a brand package soon:

I wonder if bslib should be an import 🤔
It will really only be used with those theme_* function.

So I am thinking we could make the theme Suggest and add rlang::check_installed() in each function

rlang::check_installed("bslib", "bslib is required for brand support in R", version = "0.9.0")

This trick can be used to reduce imported packages that are installed by default and not optionally. In an interactive session, this function will offer the user the opportunity to install the missing package, which is quite nice.

Usually, I try to do this when the package is used for a specific feature only, which may concern a subset of users.

I am thinking we should have done this with the specific package targeted by each function. We assume if a user was using it they would have the suggested package installed, but probably more clean to really check for it.

@gordonwoodhull
Copy link
Contributor Author

gordonwoodhull commented May 19, 2025

Good catch, bslib is suggested and not imported.

I've added rlang::check_installed for bslib and each of the theme_colors_* packages.

As we haven't released this functionality yet, I also renamed theme_*_ggplot to theme_*_ggplot2 to be correct and consistent.

@cderv cderv merged commit b178fb0 into quarto-dev:main May 19, 2025
16 checks passed
@gordonwoodhull
Copy link
Contributor Author

gordonwoodhull commented May 19, 2025

Thanks @cderv !

One related question I had was whether it is expected that all the Suggests will be installed whenever tests are run. I found some conflicting information like this

https://www.r-bloggers.com/2017/03/suggests-depends/

I do want automated tests that install and test these (to spot API breakage), but I think we have other tests that skip themselves if a suggested package is not installed,and I’d be glad to do that if it is best practice.

The smoke tests could easily do this.

@cderv
Copy link
Collaborator

cderv commented May 20, 2025

I usually follow this guideline: https://r-pkgs.org/description.html#sec-description-imports-suggests

Packages listed in Imports are needed by your users at runtime and will be installed (or potentially updated) when users install your package via install.packages().

Packages listed in Suggests are either needed for development tasks or might unlock optional functionality for your users.

So anything in Suggests must conditionally used.

I do want automated tests that install and test these (to spot API breakage), but I think we have other tests that skip themselves if a suggested package is not installed, and I’d be glad to do that if it is best practice.

No problem to add them to tests. All the package 'Imports + Suggests' are installed on CI. You can then use the skip_* helper as you saw in the test so that it does not create problem in a situation where it is not installed. Which should be rare.

All these precautions are usually relevant for CRAN publishing, and its automated testing.

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.

2 participants