From d42583986ffe1e59fb2047fe4d203829740fbef0 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:37:17 -0400 Subject: [PATCH] [r] Check that TileDB Core library versions match (#2410) (#2417) * [r] Check that library versions match * Also enable .onAttach() Co-authored-by: Dirk Eddelbuettel --- apis/r/R/Init.R | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 apis/r/R/Init.R diff --git a/apis/r/R/Init.R b/apis/r/R/Init.R new file mode 100644 index 0000000000..78cd0ef665 --- /dev/null +++ b/apis/r/R/Init.R @@ -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.") + } +}