Add support for `suggests` field in standalone files
As like #1789, I wonder suggests field should be allowed in standalone files.
For example, https://github.com/r-lib/rlang/blob/3d48c13d052724cd5997a730ea41bc8e6991691b/R/standalone-cli.R includes cli::, so the cli package is needed in the Suggests filed of the DESCRIPTION file.
Well, the reason you see cli:: in standalone-cli.R is given near the top of that file:
# Provides a minimal shim API to format message elements consistently
# with cli in packages that can't depend on it. If available, cli is
# used to format the elements. Otherwise a fallback format is used.
https://github.com/r-lib/rlang/blob/3d48c13d052724cd5997a730ea41bc8e6991691b/R/standalone-cli.R#L8-L10
Are there any r-lib standalone files that use suggests?
cc @lionel-
Well, the reason you see
cli::instandalone-cli.Ris given near the top of that file:
I understand that but unless there is cli in the Suggests field, R CMD check will show a warning.
And if we can import cli, we don't need to use the standalone-cli.R.
So I think we need suggests field.
Are there any r-lib standalone files that use
suggests?
It seems that standalone-rlang.R also needs it.
https://github.com/r-lib/rlang/blob/3d48c13d052724cd5997a730ea41bc8e6991691b/R/standalone-rlang.R#L44-L46
I think what I should really be asking is: I don't think the content of standalone-cli.R has significantly changed recently. So why have folks who use it not suffered from the lack of support for a suggests field? I just feel like I'm missing some part of the rationale.
On GitHub, all packages using that file have cli on Suggests or Imports (!).
https://github.com/search?q=path%3Aimport-standalone-cli.R&type=code
Perhaps the people using this either forgot to remove cli package from Imports, or they don't have a hard time manually adding it to Suggests
Now we're getting somewhere! @lionel- do you have any observations about this?
I agree it makes sense to add suggests field so that the standalone file works out of the box when imported.
Thanks to you both for helping advance the analysis of the problem we're trying to solve. So then ... I think this would have a companion PR in, e.g., rlang, introducing suggests fields to the standalone files that need it? Then the usethis functionality is developed to assist in placing such files (and that's what we'd test against). That's what seems like the next steps to me.
I've already created :) #2071 and r-lib/rlang#1754
I've used these on https://github.com/eitsupi/neo-r-polars and these worked (not committed though)
Another thought that this discussion has brought to my mind (but I don't know what to do about it): I wonder what fraction of packages that use standalone-cli.R (or just any particular standalone file) actually have a hard indirect dependency on cli? And I guess I also hadn't internalized that the standalone file introduces a Suggests-level dependency on cli.
But maybe cli is the wrong poster child to think about. In the sense that it's one of the packages where someone using the standalone file is pretty likely to have an indirect hard dependency on cli. standalone-purrr.R is probably a better example to keep in mind.
I think standalone-cli.R and standalone-purrr.R have completely different purposes:
standalone-cli.Ruses the functions of theclipackage if it is installed (soclishould be inSuggestsfield), but falls back to base R if it is not installed.standalone-purrr.Rprovides functions likepurrrregardless of whetherpurrris installed or not, and does not change the behavior even ifpurrris installed.
@jennybc hmm good point. In that particular case it would be kind of odd to use standalone-cli while already having a hard dep on cli. But more generally it could make sense for a standalone file to have parts of its functionality implemented with a suggest dep, and the host package could independently have a hard dep on the same package.
So I guess ideally we don't want to add a package in Suggests if it's already in Imports?
So I guess ideally we don't want to add a package in Suggests if it's already in Imports?
use_package() would not add a package to Suggests if it already exists in Imports.
https://github.com/r-lib/usethis/blob/626cc0e3fb13ea3d659ac1fc2e2e34c1bcfbc76f/R/helpers.R#L58-L64
So in my opinion #2071 works fine.
My observations really are just observations triggered by this discussion. I just meant this has me thinking through various practical aspects of standalone file usage.
For example, I hadn't fully internalized that placing standalone-cli.R requires putting cli in Suggests, in order to pass R CMD check cleanly (and I bet there are other standalone files with this same characteristic that also need suggests in their frontmatter).
I think it's telling that https://github.com/search?q=path%3Aimport-standalone-cli.R&type=code doesn't include any tidyverse or r-lib packages. Are we sure that this file is part of a workflow that we still recommend?
@hadley It was created for rlang specifically.
@lionel- it's not something we'd recommend that other people use, right?
I have never recommended it but I haven't stopped anyone from using it either. Are you thinking we should actively discourage using it?
Either way it seems like a good idea to add support for suggests fields in standalone file?
I feel like we should be very cautious about automating our standalone file approach too much. I'm worried people are going to gravitate towards when in most cases they would be better off taking an actual dependency.
I'm going to make the call here — I don't think we should attempt to 100% automate use_standalone(). It's something that folks need to use with care and thought, and manually adding a package to suggests is not a big ask.