Skip to content

Commit

Permalink
setDTthreads(2) if on CRAN #274
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Blätte authored and Andreas Blätte committed Oct 29, 2023
1 parent 49803e0 commit 82e7c92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ importFrom(data.table,key)
importFrom(data.table,melt.data.table)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
importFrom(data.table,setDTthreads)
importFrom(data.table,setcolorder)
importFrom(data.table,setindexv)
importFrom(data.table,setkey)
Expand Down
21 changes: 15 additions & 6 deletions R/zzz.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#' @importFrom data.table setDTthreads
.onLoad <- function (libname, pkgname) {

# Options are set before anything else mainly to catch the CORPUS_REGISTRY
Expand Down Expand Up @@ -38,15 +39,17 @@
# will still be a subdirectory of the inst directory. Therefore both options
# are considered whether extdata is in the inst directory, or immediately in
# main directory of the package.
pkg_registry_dir_alternatives <- c(
alt <- c(
path(libname, pkgname, "extdata", "cwb", "registry"),
path(libname, pkgname, "inst", "extdata", "cwb", "registry")
)
pkg_registry_dir <- pkg_registry_dir_alternatives[dir.exists(pkg_registry_dir_alternatives)]

pkg_indexed_corpora_dir <- path(libname, pkgname, "extdata", "cwb", "indexed_corpora")

pkg_registry_dir <- alt[dir.exists(alt)]

pkg_indexed_corpora_dir <- path(
libname, pkgname,
"extdata", "cwb", "indexed_corpora"
)

if (!dir.exists(registry())) dir.create(registry())
if (!dir.exists(data_dir())) dir.create(data_dir())

Expand All @@ -73,8 +76,14 @@
} else {
cqp_reset_registry(registry = registry())
}

}

# Limit data.table's usage to 2 threads on CRAN, cp.CRAN Repository Policy:
# "If running a package uses multiple threads/cores it must never use more
# than two simultaneously: the check farm is a shared resource and will
# typically be running many checks simultaneously."
on_cran <- !isTRUE(as.logical(Sys.getenv("NOT_CRAN", "true")))
if (on_cran) setDTthreads(2L)

NULL
}
Expand Down

0 comments on commit 82e7c92

Please sign in to comment.