Skip to content

Commit

Permalink
419: make skipping code more general to also run on old R versions (#420
Browse files Browse the repository at this point in the history
)
  • Loading branch information
danielinteractive authored Jan 26, 2024
1 parent 11d3993 commit 8d2a7d8
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 104 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: mmrm
Title: Mixed Models for Repeated Measures
Version: 0.3.8
Version: 0.3.10
Authors@R: c(
person("Daniel", "Sabanes Bove", , "daniel.sabanes_bove@roche.com", role = c("aut", "cre")),
person("Julia", "Dedic", , "julia.dedic@roche.com", role = "aut"),
Expand Down Expand Up @@ -97,7 +97,7 @@ Language: en-US
LazyData: true
NeedsCompilation: yes
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.3.0
RoxygenNote: 7.3.1
Collate:
'between-within.R'
'catch-routine-registration.R'
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# mmrm 0.3.10

### Miscellaneous

- Fix internal test skipping functions for MacOS R.

# mmrm 0.3.9

### Miscellaneous

- Fix internal test skipping functions for R versions older than 4.3.

# mmrm 0.3.8

### New Features
Expand Down
70 changes: 10 additions & 60 deletions R/skipping.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,72 +10,22 @@ is_linux <- function() {
tolower(Sys.info()[["sysname"]]) == "linux"
}

# Predicate whether currently running on R compiled with clang.
is_using_clang <- function() {
grepl("clang", R_compiled_by()["C"])
}

# A `data.frame` giving default clang versions for each OS version of the
# Fedora Linux distribution.
# Source: https://packages.fedoraproject.org/pkgs/clang/clang/
# See Updates section for older Fedora versions.
fedora_clang_defaults <- data.frame(
os = as.integer(c(36, 37, 38, 39, 40)),
clang = as.integer(c(14, 15, 16, 17, 17))
)

# A `data.frame` giving default clang versions for each OS version of the
# Debian Linux distribution.
# Source: https://packages.debian.org/search?keywords=clang
debian_clang_defaults <- data.frame(
os = c("bullseye", "bookworm", "trixie"),
clang = as.integer(c(11, 14, 16))
)

# Parse the major clang version as integer (e.g. 17) from
# the full clang string (e.g. "Debian clang version 17.0.6 (3)")
parse_clang_major <- function(clang_string) {
assert_string(clang_string, pattern = "clang")
clang_version <- gsub(pattern = "[^0-9.]", replacement = "", x = clang_string)
as.integer(gsub(pattern = "([0-9]+).+", replacement = "\\1", x = clang_version))
# Get the compiler information. Workaround for older R versions
# where R_compiled_by() is not available.
get_compiler <- function() {
r_cmd <- file.path(R.home("bin"), "R")
system2(r_cmd, args = "CMD config CC", stdout = TRUE)
}

# Predicate whether a non-standard clang version is used, specifically
# a higher than default clang version. Assumes that clang is used, otherwise fails.
# If not Fedora or Debian of the known versions are used, always returns `FALSE`.
is_non_standard_clang <- function(os_string,
clang_major_version) {
assert_string(os_string)
assert_int(clang_major_version)
if (grepl("Fedora", os_string)) {
os_version <- as.integer(gsub(pattern = "[^0-9]", replacement = "", x = os_string))
assert_int(os_version)
which_os <- match(os_version, fedora_clang_defaults$os)
if (is.na(which_os)) {
return(FALSE)
}
clang_major_version > fedora_clang_defaults$clang[which_os]
} else if (grepl("Debian", os_string)) {
os_codename <- gsub(pattern = "Debian GNU/Linux ([a-z]+)/*[a-z]*", replacement = "\\1", x = os_string)
assert_string(os_codename)
which_os <- match(os_codename, debian_clang_defaults$os)
if (is.na(which_os)) {
return(FALSE)
}
clang_major_version > debian_clang_defaults$clang[which_os]
} else {
FALSE
}
# Predicate whether currently using a clang compiler.
is_using_clang <- function() {
grepl("clang", get_compiler())
}

# Predicate whether an R-devel version is running on Linux Fedora or
# Debian with a non-standard clang compiler.
# Debian with a clang compiler.
is_r_devel_linux_clang <- function() {
is_r_devel() &&
is_linux() &&
is_using_clang() &&
is_non_standard_clang(
os_string = utils::osVersion,
clang_major_version = parse_clang_major(R_compiled_by()["C"])
)
is_using_clang()
}
3 changes: 3 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.o
*.so
*.dll
52 changes: 10 additions & 42 deletions tests/testthat/test-skipping.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,57 +10,25 @@ test_that("is_linux works as expected", {
expect_flag(is_linux())
})

# get_compiler ----

test_that("get_compiler works as expected", {
expect_string(get_compiler())
})

# is_using_clang ----

test_that("is_using_clang works as expected", {
expect_flag(is_using_clang())
})

# parse_clang_major ----

test_that("parse_clang_major works as expected", {
result <- parse_clang_major("Debian clang version 17.0.6 (3)")
expected <- 17L
test_that("is_using_clang gives the same information as R_compiled_by in recent R versions", {
skip_if(getRversion() < "4.3")
result <- is_using_clang()
expected <- grepl("clang", R_compiled_by()["C"]) # Only available from R 4.3 onward.
expect_identical(result, expected)
})

# is_non_standard_clang ----

test_that("is_non_standard_clang works as expected for Fedora", {
os_string <- "Fedora Linux 36 (Workstation Edition)"
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
expect_true(is_non_standard_clang(os_string, clang_major_version = 15L))
})

test_that("is_non_standard_clang returns FALSE for non-listed Fedora versions", {
os_string <- "Fedora Linux 12"
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
})

test_that("is_non_standard_clang works as expected for Debian", {
os_string <- "Debian GNU/Linux trixie/sid"
expect_false(is_non_standard_clang(os_string, clang_major_version = 16L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
expect_true(is_non_standard_clang(os_string, clang_major_version = 17L))
})

test_that("is_non_standard_clang returns FALSE for non-listed Debian versions", {
os_string <- "Debian GNU/Linux bla"
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
})

test_that("is_non_standard_clang returns FALSE for other Linux distributions", {
os_string <- "Solaris"
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
})

# is_r_devel_linux_clang ----

test_that("is_r_devel_linux_clang works as expected", {
Expand Down

0 comments on commit 8d2a7d8

Please sign in to comment.