Skip to content

Commit 8d2a7d8

Browse files
419: make skipping code more general to also run on old R versions (#420)
1 parent 11d3993 commit 8d2a7d8

File tree

5 files changed

+37
-104
lines changed

5 files changed

+37
-104
lines changed

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: mmrm
33
Title: Mixed Models for Repeated Measures
4-
Version: 0.3.8
4+
Version: 0.3.10
55
Authors@R: c(
66
person("Daniel", "Sabanes Bove", , "daniel.sabanes_bove@roche.com", role = c("aut", "cre")),
77
person("Julia", "Dedic", , "julia.dedic@roche.com", role = "aut"),
@@ -97,7 +97,7 @@ Language: en-US
9797
LazyData: true
9898
NeedsCompilation: yes
9999
Roxygen: list(markdown = TRUE)
100-
RoxygenNote: 7.3.0
100+
RoxygenNote: 7.3.1
101101
Collate:
102102
'between-within.R'
103103
'catch-routine-registration.R'

NEWS.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# mmrm 0.3.10
2+
3+
### Miscellaneous
4+
5+
- Fix internal test skipping functions for MacOS R.
6+
7+
# mmrm 0.3.9
8+
9+
### Miscellaneous
10+
11+
- Fix internal test skipping functions for R versions older than 4.3.
12+
113
# mmrm 0.3.8
214

315
### New Features

R/skipping.R

Lines changed: 10 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,72 +10,22 @@ is_linux <- function() {
1010
tolower(Sys.info()[["sysname"]]) == "linux"
1111
}
1212

13-
# Predicate whether currently running on R compiled with clang.
14-
is_using_clang <- function() {
15-
grepl("clang", R_compiled_by()["C"])
16-
}
17-
18-
# A `data.frame` giving default clang versions for each OS version of the
19-
# Fedora Linux distribution.
20-
# Source: https://packages.fedoraproject.org/pkgs/clang/clang/
21-
# See Updates section for older Fedora versions.
22-
fedora_clang_defaults <- data.frame(
23-
os = as.integer(c(36, 37, 38, 39, 40)),
24-
clang = as.integer(c(14, 15, 16, 17, 17))
25-
)
26-
27-
# A `data.frame` giving default clang versions for each OS version of the
28-
# Debian Linux distribution.
29-
# Source: https://packages.debian.org/search?keywords=clang
30-
debian_clang_defaults <- data.frame(
31-
os = c("bullseye", "bookworm", "trixie"),
32-
clang = as.integer(c(11, 14, 16))
33-
)
34-
35-
# Parse the major clang version as integer (e.g. 17) from
36-
# the full clang string (e.g. "Debian clang version 17.0.6 (3)")
37-
parse_clang_major <- function(clang_string) {
38-
assert_string(clang_string, pattern = "clang")
39-
clang_version <- gsub(pattern = "[^0-9.]", replacement = "", x = clang_string)
40-
as.integer(gsub(pattern = "([0-9]+).+", replacement = "\\1", x = clang_version))
13+
# Get the compiler information. Workaround for older R versions
14+
# where R_compiled_by() is not available.
15+
get_compiler <- function() {
16+
r_cmd <- file.path(R.home("bin"), "R")
17+
system2(r_cmd, args = "CMD config CC", stdout = TRUE)
4118
}
4219

43-
# Predicate whether a non-standard clang version is used, specifically
44-
# a higher than default clang version. Assumes that clang is used, otherwise fails.
45-
# If not Fedora or Debian of the known versions are used, always returns `FALSE`.
46-
is_non_standard_clang <- function(os_string,
47-
clang_major_version) {
48-
assert_string(os_string)
49-
assert_int(clang_major_version)
50-
if (grepl("Fedora", os_string)) {
51-
os_version <- as.integer(gsub(pattern = "[^0-9]", replacement = "", x = os_string))
52-
assert_int(os_version)
53-
which_os <- match(os_version, fedora_clang_defaults$os)
54-
if (is.na(which_os)) {
55-
return(FALSE)
56-
}
57-
clang_major_version > fedora_clang_defaults$clang[which_os]
58-
} else if (grepl("Debian", os_string)) {
59-
os_codename <- gsub(pattern = "Debian GNU/Linux ([a-z]+)/*[a-z]*", replacement = "\\1", x = os_string)
60-
assert_string(os_codename)
61-
which_os <- match(os_codename, debian_clang_defaults$os)
62-
if (is.na(which_os)) {
63-
return(FALSE)
64-
}
65-
clang_major_version > debian_clang_defaults$clang[which_os]
66-
} else {
67-
FALSE
68-
}
20+
# Predicate whether currently using a clang compiler.
21+
is_using_clang <- function() {
22+
grepl("clang", get_compiler())
6923
}
7024

7125
# Predicate whether an R-devel version is running on Linux Fedora or
72-
# Debian with a non-standard clang compiler.
26+
# Debian with a clang compiler.
7327
is_r_devel_linux_clang <- function() {
7428
is_r_devel() &&
7529
is_linux() &&
76-
is_using_clang() &&
77-
is_non_standard_clang(
78-
os_string = utils::osVersion,
79-
clang_major_version = parse_clang_major(R_compiled_by()["C"])
80-
)
30+
is_using_clang()
8131
}

src/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*.o
2+
*.so
3+
*.dll

tests/testthat/test-skipping.R

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,57 +10,25 @@ test_that("is_linux works as expected", {
1010
expect_flag(is_linux())
1111
})
1212

13+
# get_compiler ----
14+
15+
test_that("get_compiler works as expected", {
16+
expect_string(get_compiler())
17+
})
18+
1319
# is_using_clang ----
1420

1521
test_that("is_using_clang works as expected", {
1622
expect_flag(is_using_clang())
1723
})
1824

19-
# parse_clang_major ----
20-
21-
test_that("parse_clang_major works as expected", {
22-
result <- parse_clang_major("Debian clang version 17.0.6 (3)")
23-
expected <- 17L
25+
test_that("is_using_clang gives the same information as R_compiled_by in recent R versions", {
26+
skip_if(getRversion() < "4.3")
27+
result <- is_using_clang()
28+
expected <- grepl("clang", R_compiled_by()["C"]) # Only available from R 4.3 onward.
2429
expect_identical(result, expected)
2530
})
2631

27-
# is_non_standard_clang ----
28-
29-
test_that("is_non_standard_clang works as expected for Fedora", {
30-
os_string <- "Fedora Linux 36 (Workstation Edition)"
31-
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
32-
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
33-
expect_true(is_non_standard_clang(os_string, clang_major_version = 15L))
34-
})
35-
36-
test_that("is_non_standard_clang returns FALSE for non-listed Fedora versions", {
37-
os_string <- "Fedora Linux 12"
38-
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
39-
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
40-
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
41-
})
42-
43-
test_that("is_non_standard_clang works as expected for Debian", {
44-
os_string <- "Debian GNU/Linux trixie/sid"
45-
expect_false(is_non_standard_clang(os_string, clang_major_version = 16L))
46-
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
47-
expect_true(is_non_standard_clang(os_string, clang_major_version = 17L))
48-
})
49-
50-
test_that("is_non_standard_clang returns FALSE for non-listed Debian versions", {
51-
os_string <- "Debian GNU/Linux bla"
52-
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
53-
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
54-
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
55-
})
56-
57-
test_that("is_non_standard_clang returns FALSE for other Linux distributions", {
58-
os_string <- "Solaris"
59-
expect_false(is_non_standard_clang(os_string, clang_major_version = 14L))
60-
expect_false(is_non_standard_clang(os_string, clang_major_version = 13L))
61-
expect_false(is_non_standard_clang(os_string, clang_major_version = 15L))
62-
})
63-
6432
# is_r_devel_linux_clang ----
6533

6634
test_that("is_r_devel_linux_clang works as expected", {

0 commit comments

Comments
 (0)