From 7814227c03ab37fe8eefd6248473b5a5265c68ac Mon Sep 17 00:00:00 2001 From: 2005m Date: Mon, 26 Feb 2024 23:07:47 +0000 Subject: [PATCH] Fix OnAttach --- MD5 | 6 +++--- R/call.R | 18 ++++++++++++------ tests/test_kit.R | 1 - tests/test_kit.Rout.save | 2 -- 4 files changed, 15 insertions(+), 12 deletions(-) diff --git a/MD5 b/MD5 index 6b41656..27fd52c 100644 --- a/MD5 +++ b/MD5 @@ -16,7 +16,7 @@ a137f7855b41b074e2babaf8a1562551 *man/shareData.Rd 54f91d543a10f8c9aef7082da2b86de7 *man/topn.Rd a7f31cee15b9624dab8f4d13d3c66bad *man/vswitch.Rd c797ca387dccc02751cfe85108fb0159 *NAMESPACE -a19c6faffef01603c022f6291d46bf21 *R/call.R +82928f8fb69a52a14469d8e1f225ba3d *R/call.R 2d6c06dfc570d456af125c160cf150d7 *README.md b68e68fed386fa0ce15ec6ec2e1f91a5 *src/dup.c 17b8c354cd84b5d85ab5a62ef2bfab4e *src/dupLen.c @@ -33,5 +33,5 @@ bafdafd654269acd054525571dbe1b44 *src/share.c 53711690f6c15f3f36edb4b9360043a4 *src/topn.c b9daa73f97bb19027aaa5bfdc00c4087 *src/utils.c 3476a1e2381bb86f68a72844ee61bc7b *src/vswitch.c -3f8dc4ecf4ad26fb959a2291ab167630 *tests/test_kit.R -f0b7442cb1c46dd6a5f7344199bc1ac4 *tests/test_kit.Rout.save +b28a565eeb0b8e5f7e2969be373d32f4 *tests/test_kit.R +84aecd97807e8ec130ee14422da21389 *tests/test_kit.Rout.save diff --git a/R/call.R b/R/call.R index 9b171f7..47bed43 100644 --- a/R/call.R +++ b/R/call.R @@ -27,14 +27,20 @@ topn = function(vec, n=6L, decreasing=TRUE, hasna=TRUE,index=TRUE) if(ind uniqLen = function(x) .Call(CdupLenR, x) vswitch = function(x, values, outputs, default=NULL, nThread=getOption("kit.nThread"), checkEnc = TRUE) .Call(CvswitchR, x, values, outputs, default, nThread, checkEnc) -.onAttach = function(libname, pkgname) packageStartupMessage(paste0("Attaching kit 0.0.16 (OPENMP ",if(.Call(CompEnabledR)) "enabled" else "disabled"," using 1 thread)")) .onUnload = function(libpath) library.dynam.unload("kit", libpath) #nocov -.onLoad = function(libname, pkgname) { - if (!("kit.nThread" %in% names(options()))) { - options("kit.nThread"=1L) - } -} +.onAttach = function(libname, pkgname) { #nocov + omp = if(.Call(CompEnabledR)) "enabled" else "disabled" #nocov + nth = getOption("kit.nThread") #nocov + thd = if (nth > 1L) " threads)" else " thread)" #nocov + packageStartupMessage(paste0("Attaching kit 0.0.16 (OPENMP ",omp," using ",nth,thd)) #nocov +} #nocov + +.onLoad = function(libname, pkgname) { #nocov + if (!("kit.nThread" %in% names(options()))) { #nocov + options("kit.nThread"=1L) #nocov + } #nocov +} #nocov pcount = function(..., value) { if(is.na(value[1])) { diff --git a/tests/test_kit.R b/tests/test_kit.R index de0b8ba..b76c236 100644 --- a/tests/test_kit.R +++ b/tests/test_kit.R @@ -33,7 +33,6 @@ check = function(test,x,y,error=NULL,warning=NULL) { return(invisible(FALSE)) } -library(kit); unloadNamespace("kit") topn = kit::topn setlevels = kit::setlevels diff --git a/tests/test_kit.Rout.save b/tests/test_kit.Rout.save index cf06fff..0009199 100644 --- a/tests/test_kit.Rout.save +++ b/tests/test_kit.Rout.save @@ -52,8 +52,6 @@ Type 'q()' to quit R. + return(invisible(FALSE)) + } > -> library(kit); unloadNamespace("kit") -Attaching kit 0.0.16 (OPENMP enabled using 1 thread) > > topn = kit::topn > setlevels = kit::setlevels