Skip to content

Commit

Permalink
[r] Check that TileDB Core library versions match (#2410) (#2417)
Browse files Browse the repository at this point in the history
* [r] Check that library versions match

* Also enable .onAttach()

Co-authored-by: Dirk Eddelbuettel <[email protected]>
  • Loading branch information
github-actions[bot] and eddelbuettel authored Apr 9, 2024
1 parent d1ee1a4 commit d425839
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions apis/r/R/Init.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## .onLoad is called whether code from the package is used and the packages is 'loaded'. An
## example is calling `tiledbsoma::show_package_versions()`. So this is most elementary check,
## .onAttach is also called when the package is 'attached' via 'library(tiledbsoma)'
## During package build and byte-code compilation and load check, both are called.
.onLoad <- function(libname, pkgname) {
rpkg_lib_version <- tiledb::tiledb_version(compact=TRUE)
soma_lib_version <- libtiledbsoma_version(compact=TRUE)
if (rpkg_lib_version != soma_lib_version) {
msg <- sprintf("TileDB Core version %s used by TileDB-R package, but TileDB-SOMA uses %s",
sQuote(rpkg_lib_version), sQuote(soma_lib_version))
stop(msg, call. = FALSE)
}
}

## An .onAttach() function is not allowed to use cat() etc but _must_ communicate via
## packageStartupMessage() as this function can be 'muzzled' as desired. See Writing R Extensions.
.onAttach <- function(libname, pkgname) {
if (interactive()) {
packageStartupMessage("TileDB-SOMA R package ", packageVersion(pkgname),
" with TileDB Embedded ", format(tiledb::tiledb_version(TRUE)),
" on ", utils::osVersion,
".\nSee https://github.com/single-cell-data for more information ",
"about the SOMA project.")
}
}

0 comments on commit d425839

Please sign in to comment.