Skip to content

feat: add use_extendr_badge() #417

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 8 commits into from
Aug 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export(rust_source)
export(to_toml)
export(use_crate)
export(use_extendr)
export(use_extendr_badge)
export(use_msrv)
export(use_positron)
export(use_vscode)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Adds [WebR](https://docs.r-wasm.org/webr/latest/) support out of the box for all extendr packages.
* Note that not all Rust crates are wasm compatible. This change only enables the package to build in the `wasm32-unknown-emscripten` target. It does not guarantee all dependencies will compile.
* Addresses new CRAN check in R 4.5+ adding warning for `_abort` usage
* `use_extendr_badge()` has been added to add an extendr-specific badge to a `README.Rmd` via `usethis::use_badge()` <https://github.com/extendr/rextendr/pull/417>
* Removes `Makevars.ucrt` as R versions < 4.1 are not supported by extendr <https://github.com/extendr/rextendr/pull/414>
* `purrr` has been replaced with [`R/standalone-purrr.R`](https://github.com/r-lib/rlang/blob/main/R/standalone-purrr.R) removing `purrr` from `Imports` <https://github.com/extendr/rextendr/pull/408>
* `document()` will no longer try to save all open files using rstudioapi <https://github.com/extendr/rextendr/issues/404> <https://github.com/extendr/rextendr/issues/407>
Expand Down
35 changes: 35 additions & 0 deletions R/badge.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#' extendr README badge
#'
#' Add the version of extendr being used by an R package to its README.
#'
#' Requires `usethis` to be available.
#'
#' @examples
#' \dontrun{
#' use_extendr_badge()
#' }
#'
#' @inheritParams use_extendr
#' @export
use_extendr_badge <- function(path = ".") {
rlang::check_installed("usethis")
meta <- read_cargo_metadata(path)
deps <- meta[[c("packages", "dependencies")]][[1]]

if (rlang::is_null(deps)) {
cli::cli_abort("Unable to determine version of `extendr-api`")
}

is_extendr <- which(deps$name == "extendr-api")
if (!rlang::is_bare_numeric(is_extendr, 1)) {
cli::cli_abort("Unable to determine version of `extendr-api`")
}

extendr_version <- deps$req[is_extendr]

usethis::use_badge(
"extendr",
"https://extendr.github.io/extendr/extendr_api/",
sprintf("https://img.shields.io/badge/extendr-%s-276DC2", extendr_version)
)
}
4 changes: 4 additions & 0 deletions R/use_extendr.R
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,10 @@ use_extendr <- function(
"Please run {.fun rextendr::document} for changes to take effect."
)
)
# encourage use of use_extendr__badge
cli::cli_alert_info(
"Call {.fn use_extendr_badge} to add an extendr badge to your {.file README}"
)
}

return(invisible(TRUE))
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ reference:
- make_module_macro
- rust_sitrep
- read_cargo_metadata
- use_extendr_badge
23 changes: 23 additions & 0 deletions man/use_extendr_badge.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/_snaps/cran-compliance.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
3 extendr-macros *.*.*
4 once_cell *.*.*
5 paste *.*.*
6 proc-macro2 *.*.*
6 proc-macro2 *.*.*
7 quote *.*.*
8 syn *.*.*
9 unicode-ident *.*.*
Expand Down
2 changes: 2 additions & 0 deletions tests/testthat/_snaps/use_extendr.md
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@
> File 'configure.win' already exists. Skip writing the file.
v Finished configuring extendr for package testpkg.wrap.
* Please run `rextendr::document()` for changes to take effect.
i Call `use_extendr_badge()` to add an extendr badge to your 'README'

# use_extendr() can overwrite files in non-interactive sessions

Expand All @@ -390,6 +391,7 @@
v Writing 'configure.win'
v Finished configuring extendr for package testpkg.
* Please run `rextendr::document()` for changes to take effect.
i Call `use_extendr_badge()` to add an extendr badge to your 'README'

---

Expand Down
Loading