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 inline R code for badges #17

Closed
wlandau opened this issue Aug 10, 2019 · 12 comments
Closed

Use inline R code for badges #17

wlandau opened this issue Aug 10, 2019 · 12 comments

Comments

@wlandau
Copy link

wlandau commented Aug 10, 2019

Would you help me understand why usethis::use_lifecycle() adds lifecycle to Imports rather than Suggests?

> library(usethis)
> use_lifecycle()
✔ Setting active project to '/home/landau/projects/drake'Adding 'lifecycle' to Imports field in DESCRIPTION
...

I am new to lifecycle, and I am happy to see that tidyverse lifecycle badges have become more widely available.

@lionel-
Copy link
Member

lionel- commented Aug 10, 2019

It's only needed for deprecated functions really. You might want to wait before we publish the blog post though, there are last minute UI discussions going on ;). Also we'll change some of the badge colours.

@lionel-
Copy link
Member

lionel- commented Aug 10, 2019

Sratch that, lifecycle::badge() must be available at runtime so the HTML documentation can be rendered. So that's Imports, not Suggests. It's a lightweight dependency though. Maybe I'll create a base R compat-badge.R file for those who only want the badges.

@wlandau
Copy link
Author

wlandau commented Aug 11, 2019

Thanks for explaining, @lionel-.

The badges show up correctly when I copy the output of cat(badge()) and paste it at the end of the @title. You have made that part so easy that I am likely to skip the Rd macro to avoid incurring another package dependency, however light.

@wlandau
Copy link
Author

wlandau commented Aug 11, 2019

Hmm... maybe not. The code creates long lines, so the macros are actually really handy.

@lionel-
Copy link
Member

lionel- commented Aug 12, 2019

I think if you just copy badge.R in your package, and make the macro call mypkg:::badge.R(), this should work without the dependency.

@wlandau
Copy link
Author

wlandau commented Aug 12, 2019

Sounds reasonable, thanks. I will go with that.

@wlandau wlandau closed this as completed Aug 12, 2019
@lionel- lionel- reopened this Aug 13, 2019
@hadley
Copy link
Member

hadley commented Mar 5, 2020

In the next version of roxygen you'll be able to do :

#' `r lifecycle::badge("deprecated")`

That will run badge() at document time, so lifecycle won't need to be in imports and you don't need some other compat layer. I've changed the title to reflect the work that'll need to be done when the next version of roxygen2 is out.

@hadley hadley changed the title The role of lifecycle as a package dependency Use inline R code for badges Mar 5, 2020
@jennybc
Copy link
Member

jennybc commented Jun 11, 2020

@lionel- When you do this, will you also determine if usethis::use_lifecycle() needs an associated update?

https://github.com/r-lib/usethis/blob/9b462b1918bb1e089d3160724131dfa6746fb1fa/R/lifecycle.R#L21

@krlmlr
Copy link
Member

krlmlr commented Jun 14, 2020

For updating existing code with GNU sed:

sed -r -i 's/\\lifecycle[{](.*)[}]/`r lifecycle::badge("\1")`/' R/*

@lionel-
Copy link
Member

lionel- commented Jun 15, 2020

Thanks Kirill! This variant may also be useful with the old lifecycle compat files:

gsed -r -i 's/\\Sexpr\[results=rd, stage=render\][{]rlang:::lifecycle\((.*)\)[}]/`r lifecycle::badge(\1)`/' R/*

@lionel-
Copy link
Member

lionel- commented Jun 15, 2020

Looks like we'll need r-lib/roxygen2#1115 solved first.

@krlmlr
Copy link
Member

krlmlr commented Jun 15, 2020

The great thing about develop-time dependencies: you can install locally from a branch 🙃

@lionel- lionel- closed this as completed in 6417f39 Jan 4, 2021
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

No branches or pull requests

5 participants