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

Bump minimum R version #2265

Merged
merged 8 commits into from
Nov 12, 2023
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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ License: MIT + file LICENSE
URL: https://github.com/r-lib/lintr, https://lintr.r-lib.org
BugReports: https://github.com/r-lib/lintr/issues
Depends:
R (>= 3.5)
R (>= 3.6)
Imports:
backports (>= 1.1.7),
codetools,
Expand Down
7 changes: 2 additions & 5 deletions R/settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ read_config_file <- function(config_file) {

config <- new.env()
if (endsWith(config_file, ".R")) {
load_config <- function(file) sys_source(file, config)
load_config <- function(file) sys.source(file, config, keep.source = FALSE, keep.parse.data = FALSE)
malformed <- function(e) {
stop("Malformed config file, ensure it is valid R syntax\n ", conditionMessage(e), call. = FALSE)
}
Expand Down Expand Up @@ -231,10 +231,7 @@ get_encoding_from_dcf <- function(file) {
warning = function(e) NULL
)

if (!is.null(encodings)) {
# Produces a warning in R <= 3.5 if encoding is NULL
encodings <- encodings[!is.na(encodings)]
}
encodings <- encodings[!is.na(encodings)]
if (length(encodings) > 0L) {
return(encodings[1L])
}
Expand Down
2 changes: 1 addition & 1 deletion R/shared_constants.R
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ names(infix_metadata) <- c("xml_tag", "string_value")
# utils::getParseData()'s designation for the tokens wouldn't be valid as XML tags
infix_metadata$parse_tag <- ifelse(
startsWith(infix_metadata$xml_tag, "OP-"),
quote_wrap(infix_metadata$string_value, "'"),
sQuote(infix_metadata$string_value, "'"),
infix_metadata$xml_tag
)
# treated separately because spacing rules are different for unary operators
Expand Down
3 changes: 0 additions & 3 deletions R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,6 @@ try_silently <- function(expr) {
)
}

# imitate sQuote(x, q) [requires R>=3.6]
quote_wrap <- function(x, q) paste0(q, x, q)

# interface to work like options() or setwd() -- returns the old value for convenience
set_lang <- function(new_lang) {
old_lang <- Sys.getenv("LANGUAGE", unset = NA)
Expand Down
4 changes: 2 additions & 2 deletions R/xp_utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ xp_text_in_table <- function(table) {
# to use "" whenever the string has ' (not a perfect solution). info on
# escaping from https://stackoverflow.com/questions/14822153
single_quoted <- grepl("'", table, fixed = TRUE)
table[single_quoted] <- quote_wrap(table[single_quoted], '"')
table[!single_quoted] <- quote_wrap(table[!single_quoted], "'")
table[single_quoted] <- sQuote(table[single_quoted], '"')
table[!single_quoted] <- sQuote(table[!single_quoted], "'")
return(paste0("text() = ", table, collapse = " or "))
}

Expand Down
21 changes: 0 additions & 21 deletions R/zzz.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,18 +282,6 @@ default_undesirable_operators <- all_undesirable_operators[names(all_undesirable
#' @export
default_settings <- NULL

# TODO(R>=3.6.0): Just use sys.source() directly. Note that we can't
# write a wrapper that only passes keep.parse.data=FALSE on R>3.5.0
# (without doing some wizardry to evade R CMD check) because
# there is a check for arguments not matching the signature which
# will throw a false positive on R3.5.0. Luckily the argument
# defaults on R>=3.6.0 are dictated by global options, so we can use
# that for the wrapper here rather than doing some NSE tricks.
sys_source <- function(...) {
old <- options(keep.source.pkgs = FALSE, keep.parse.data.pkgs = FALSE)
on.exit(options(old))
sys.source(...)
}
settings <- new.env(parent = emptyenv())

# nocov start
Expand All @@ -305,18 +293,9 @@ settings <- new.env(parent = emptyenv())
toset <- !(names(op_lintr) %in% names(op))
if (any(toset)) options(op_lintr[toset])

# R>=3.6.0: str2expression, str2lang
# R>=4.0.0: deparse1
# R>=4.1.0: ...names
backports::import(pkgname, c("deparse1", "...names"))
base_ns <- getNamespace("base")
backports_ns <- getNamespace("backports")
lintr_ns <- getNamespace(pkgname)
for (base_fun in c("str2lang", "str2expression")) {
if (!exists(base_fun, base_ns)) {
assign(base_fun, get(base_fun, backports_ns), lintr_ns)
}
}

utils::assignInMyNamespace("default_settings", list(
linters = default_linters,
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-lint_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ test_that("package using .lintr.R config lints correctly", {
})

test_that("lintr need not be attached for .lintr.R configs to use lintr functions", {
skip_if_not_r_version("3.6.0") # unclear error message
exprs <- paste(
'options(lintr.linter_file = "lintr_test_config")',
sprintf('lints <- lintr::lint_package("%s")', test_path("dummy_packages", "RConfig")),
Expand Down
Loading