Skip to content

Commit

Permalink
Work around a bug in R 4.1
Browse files Browse the repository at this point in the history
R 4.1 has an obscure bug in `get0('.First')`, which causes the function
to return `NULL` instead of `ifnotfound`, unless `mode` is specified,
because `.First` is defined as `NULL` in the ‘base’ package:

```
> get0('.First', ifnotfound = 42)
NULL
> get0('.First', mode = 'function', ifnotfound = 42)
[1] 42
```
  • Loading branch information
klmr committed Feb 6, 2024
1 parent 06c6b24 commit 30e366d
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/testthat/support/rprofile.r
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ local({
sys.source(user_profile, envir = .GlobalEnv)
}

old_first = get0('.First', envir = .GlobalEnv, ifnotfound = function () {})
old_first = get0('.First', envir = .GlobalEnv, mode = 'function', ifnotfound = function () {})
.GlobalEnv$.First = function () {
old_first()
# This is required by `interactive_r` to verify that invocation succeeded.
Expand Down

0 comments on commit 30e366d

Please sign in to comment.