Skip to content

Commit 40afa84

Browse files
ben-schwenMichaelChiricoTyson Barrett
authored
Fix onLoad for devtools::load_all() (#5828)
* check if builtPath exists * fix builtPath * update dev README * make file.path platform independent Co-authored-by: Michael Chirico <[email protected]> * soften language around the use of cc() * cache r versino * clarify dev README * update comment * rename variable for consistency --------- Co-authored-by: Michael Chirico <[email protected]> Co-authored-by: Tyson Barrett <[email protected]> Co-authored-by: Michael Chirico <[email protected]>
1 parent 15c127e commit 40afa84

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

.dev/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
# data.table developer
22

3+
## Setup
4+
5+
To use the optional helper function `cc()`, one needs to set up the project path and source `.dev/cc.R` to use `cc()` conveniently. This works through creating an additional `.Rprofile` in the `data.table` directory.
6+
7+
```r
8+
# content of .Rprofile in the package directory
9+
Sys.setenv(PROJ_PATH="~/git/data.table")
10+
source(".dev/cc.R")
11+
```
12+
313
## Utilities
414

515
### [`cc.R`](./cc.R)

R/onLoad.R

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
.Last.updated = vector("integer", 1L) # exported variable; number of rows updated by the last := or set(), #1885
1616

1717
.onLoad = function(libname, pkgname) {
18+
session_r_version = base::getRversion()
1819
# Runs when loaded but not attached to search() path; e.g., when a package just Imports (not Depends on) data.table
1920
if (!exists("test.data.table", .GlobalEnv, inherits=FALSE)) {
2021
# check when installed package is loaded but skip when developing the package with cc()
@@ -25,9 +26,9 @@
2526
# https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17478
2627
stopf("The data_table.%s version (%s) does not match the package (%s). Please close all R sessions to release the old %s and reinstall data.table in a fresh R session. The root cause is that R's package installer can in some unconfirmed circumstances leave a package in a state that is apparently functional but where new R code is calling old C code silently: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=17478. Once a package is in this mismatch state it may produce wrong results silently until you next upgrade the package. Please help by adding precise circumstances to 17478 to move the status to confirmed. This mismatch between R and C code can happen with any package not just data.table. It is just that data.table has added this check.", dll, dllV, RV, toupper(dll))
2728
}
28-
builtUsing = readRDS(system.file("Meta/package.rds",package="data.table"))$Built$R
29-
if (!identical(base::getRversion()>="4.0.0", builtUsing>="4.0.0")) {
30-
stopf("This is R %s but data.table has been installed using R %s. The major version must match. Please reinstall data.table.", base::getRversion(), builtUsing)
29+
builtPath = system.file("Meta", "package.rds", package="data.table")
30+
if (builtPath != "" && !identical(session_r_version>="4.0.0", (build_r_version <- readRDS(builtPath)$Built$R)>="4.0.0")) {
31+
stopf("This is R %s but data.table has been installed using R %s. The major version must match. Please reinstall data.table.", session_r_version, build_r_version)
3132
# the if(R>=4.0.0) in NAMESPACE when registering S3 methods rbind.data.table and cbind.data.table happens on install; #3968
3233
}
3334
}
@@ -37,7 +38,7 @@
3738
# be conditional too: registering the S3 methods in R before 4.0.0 causes this workaround to no longer work. However, the R
3839
# syntax available to use in NAMESPACE is very limited (can't call data.table() in it in a capability test, for example).
3940
# This version number ("4.0.0") must be precisely the same as used in NAMESPACE; see PR for #3948.
40-
if (base::getRversion() < "4.0.0") {
41+
if (session_r_version < "4.0.0") {
4142
# continue to support R<4.0.0
4243
# If R 3.6.2 (not yet released) includes the c|rbind S3 dispatch fix, then this workaround still works.
4344
tt = base::cbind.data.frame

0 commit comments

Comments
 (0)