.hgrt <- new.env()
#' @importFrom reticulate import
.onLoad <- function(libname, pkgname) {
set_env()
}
#' @importFrom reticulate conda_create
set_env <- function() {
if (!check_conda_set()) {
reticulate::conda_create("r-hgr.tokenizers", packages = "python=3.7")
}
if (!check_env()) {
install_conda_packages()
}
}
#' @importFrom reticulate conda_install
install_conda_packages <- function() {
reticulate::conda_install("r-hgr.tokenizers",
pip = TRUE,
packages = c("tokenizers==0.9.3"))
cat("\nInstallation complete.\n\n")
}
#' @importFrom reticulate py_module_available
check_env <- function() {
reticulate::py_module_available("tokenizers")
}
#' @importFrom reticulate use_condaenv
check_conda_set <- function() {
chk <-
try(reticulate::use_condaenv("r-hgr.tokenizers", required = TRUE), silent = T)
if (class(chk) == "try-error") {
res <- F
} else {
res <- T
}
return(res)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.