Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .lintr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
linters: all_linters(
backport_linter("3.6.0", except = c("R_user_dir", "deparse1", "...names")),
backport_linter("auto", except = c("R_user_dir", "deparse1", "...names")),
line_length_linter(120L),
object_overwrite_linter(allow_names = c("line", "lines", "pipe", "symbols")),
todo_comment_linter(
Expand Down
11 changes: 11 additions & 0 deletions R/backport_linter.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#' @param r_version Minimum R version to test for compatibility. Defaults to
#' the R version currently in use. The version can be specified as a version
#' number, or as a version alias (such as `"devel"`, `"oldrel"`, `"oldrel-1"`).
#' It can also be `"auto"` to use the minimum R version declared in the
#' `DESCRIPTION` file of R packages.
#' @param except Character vector of functions to be excluded from linting.
#' Use this to list explicitly defined backports, e.g. those imported from the `{backports}` package or manually
#' defined in your package.
Expand Down Expand Up @@ -120,6 +122,15 @@ normalize_r_version <- function(r_version) {
))

r_version <- R_system_version(available_patches[selected_patch])
} else if (identical(r_version, "auto")) {
r_version <- min_r_version()
if (is.na(r_version)) {
cli_warn(c(
x = "No DESCRIPTION file or no specified minimum R version could be found.",
i = "Setting {.arg r_version} to the currently running R version (R {getRversion()})."
))
r_version <- getRversion()
}
} else if (is.character(r_version)) {
r_version <- R_system_version(r_version, strict = TRUE)
} else if (!inherits(r_version, "R_system_version")) {
Expand Down
20 changes: 20 additions & 0 deletions R/settings_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,23 @@
nm <- read.dcf(file.path(path, "DESCRIPTION"), fields = "Package")[1L]
if (!is.na(nm)) nm
}

min_r_version <- function(path = find_package(".")) {
if (is.null(path)) {
return(NA_character_)
}
depends_field <- read.dcf(file.path(path, "DESCRIPTION"), fields = "Depends")

depends <- trimws(strsplit(depends_field, ",", fixed = TRUE)[[1L]])

min_r_ver <- gsub("^R \\(>=?\\s(.+)\\)", "\\1", grep("R ", depends, value = TRUE, fixed = TRUE))

if (length(min_r_ver) == 0) {

Check warning on line 126 in R/settings_utils.R

View workflow job for this annotation

GitHub Actions / lint

file=R/settings_utils.R,line=126,col=29,[implicit_integer_linter] Use 0L or 0.0 to avoid implicit integers.
return(NA_character_)
}
# According to 'Writing R Extensions', the trailing 0 for patch version can
# be dropped.
# But we want to identically match an existing version number so we add it if
# it's missing.
gsub("^(\\d+\\.\\d+)$", "\\1.0", min_r_ver)
}
4 changes: 3 additions & 1 deletion man/backport_linter.Rd

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

Loading