Skip to content

Commit 646270c

Browse files
committed
add use_extendr_badge()
1 parent cbd93f6 commit 646270c

File tree

5 files changed

+78
-0
lines changed

5 files changed

+78
-0
lines changed

R/badge.R

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#' extendr README badge
2+
#'
3+
#' Add the version of extendr being used by an R package to its README.
4+
#'
5+
#' Requires `usethis` to be available.
6+
#'
7+
#' @examples
8+
#' \dontrun{
9+
#' use_extendr_badge()
10+
#' }
11+
#'
12+
#' @inheritParams use_extendr
13+
use_extendr_badge <- function(path = ".") {
14+
rlang::check_installed("usethis")
15+
meta <- read_cargo_metadata(path)
16+
deps <- meta[[c("packages", "dependencies")]][[1]]
17+
18+
if (rlang::is_null(deps)) {
19+
cli::cli_abort("Unable to determine version of `extendr-api`")
20+
}
21+
22+
is_extendr <- which(deps$name == "extendr-api")
23+
if (!rlang::is_bare_numeric(is_extendr, 1)) {
24+
cli::cli_abort("Unable to determine version of `extendr-api`")
25+
}
26+
27+
extendr_version <- deps$req[is_extendr]
28+
29+
usethis::use_badge(
30+
"extendr",
31+
"https://extendr.github.io/extendr/extendr_api/",
32+
sprintf("https://img.shields.io/badge/extendr-%s-276DC2", extendr_version)
33+
)
34+
}

R/use_extendr.R

+6
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,9 @@ use_extendr <- function(path = ".",
206206
Sys.chmod("configure", "0755")
207207
}
208208

209+
# Set the minimum version of R to 4.2 as now required by libR-sys 0.7
210+
usethis::use_package("R", "Depends", "4.2")
211+
209212
# the temporary cargo directory must be ignored
210213
usethis::use_build_ignore("src/.cargo")
211214

@@ -225,6 +228,9 @@ use_extendr <- function(path = ".",
225228
usethis::use_build_ignore("src/Makevars.win")
226229
usethis::use_git_ignore("src/Makevars.win")
227230

231+
232+
use_extendr_badge()
233+
228234
if (!isTRUE(quiet)) {
229235
cli::cli_alert_success("Finished configuring {.pkg extendr} for package {.pkg {pkg_name}}.")
230236
cli::cli_ul(

README.Rmd

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ knitr::opts_chunk$set(
2222
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
2323
[![R build status](https://github.com/extendr/rextendr/workflows/R-CMD-check/badge.svg)](https://github.com/extendr/rextendr/actions)
2424
[![Codecov test coverage](https://codecov.io/gh/extendr/rextendr/graph/badge.svg)](https://app.codecov.io/gh/extendr/rextendr)
25+
[![extendr](https://img.shields.io/badge/extendr-^0.7.1-276DC2)](https://extendr.github.io/extendr/extendr_api/)
2526
<!-- badges: end -->
2627

2728
## Installation

man/use_extendr_badge.Rd

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/_snaps/use_extendr.md

+14
Original file line numberDiff line numberDiff line change
@@ -410,6 +410,13 @@
410410
> File 'tools/msrv.R' already exists. Skip writing the file.
411411
> File 'configure' already exists. Skip writing the file.
412412
> File 'configure.win' already exists. Skip writing the file.
413+
! Can't find a README for the current project.
414+
i See `usethis::use_readme_rmd()` for help creating this file.
415+
i Badge link will only be printed to screen.
416+
[ ] Copy and paste the following lines into 'README':
417+
<!-- badges: start -->
418+
[![extendr](https://img.shields.io/badge/extendr-*-276DC2)](https://extendr.github.io/extendr/extendr_api/)
419+
<!-- badges: end -->
413420
v Finished configuring extendr for package testpkg.wrap.
414421
* Please run `rextendr::document()` for changes to take effect.
415422

@@ -430,6 +437,13 @@
430437
v Writing 'tools/msrv.R'
431438
v Writing 'configure'
432439
v Writing 'configure.win'
440+
! Can't find a README for the current project.
441+
i See `usethis::use_readme_rmd()` for help creating this file.
442+
i Badge link will only be printed to screen.
443+
[ ] Copy and paste the following lines into 'README':
444+
<!-- badges: start -->
445+
[![extendr](https://img.shields.io/badge/extendr-*-276DC2)](https://extendr.github.io/extendr/extendr_api/)
446+
<!-- badges: end -->
433447
v Finished configuring extendr for package testpkg.
434448
* Please run `rextendr::document()` for changes to take effect.
435449

0 commit comments

Comments
 (0)