Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 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,8 @@ 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()
} 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
17 changes: 17 additions & 0 deletions R/settings_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,20 @@ pkg_name <- function(path = find_package()) {
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(getRversion())
}
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))

# 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