Skip to content

Commit

Permalink
🚸 Check attaching to environment in install_lamindb() (#135)
Browse files Browse the repository at this point in the history
* 🚸 Check attaching in install_lamindb()

* Update R/install.R

---------

Co-authored-by: Robrecht Cannoodt <[email protected]>
  • Loading branch information
lazappi and rcannood authored Jan 8, 2025
1 parent a555bf2 commit e8c801c
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#' @param new_env Whether to remove any existing `virtualenv` with the same name
#' before creating a new one with the requested packages
#'
#' @return The result of `reticulate::py_install()`
#' @return `NULL`, invisibly
#' @export
#'
#' @details
Expand All @@ -35,10 +35,35 @@ install_lamindb <- function(..., envname = "r-lamindb", extra_packages = NULL,
reticulate::virtualenv_remove(envname)
}

packages <- unique(c(
"lamindb",
"ipython",
extra_packages
))
packages <- unique(c("lamindb", "ipython", extra_packages))

reticulate::py_install(packages = packages, envname = envname, ...)

env_type <-
if (reticulate::virtualenv_exists(envname)) {
"virtualenv"
} else if (reticulate::condaenv_exists(envname)) {
"conda"
} else {
cli::cli_abort(paste(
"Neither a virtualenv or conda environment with the name {.val {envname}} exists.",
"The installation may have failed."
))
}

tryCatch(
switch(
env_type,
virtualenv = reticulate::use_virtualenv(envname),
conda = reticulate::use_condaenv(envname)
),
error = function(err) {
cli::cli_warn(paste(
"Unable to attach to the {.val {envname}} {env_type} environment.",
"Try starting a new R session before using {.pkg laminr}."
))
}
)

invisible(NULL)
}

0 comments on commit e8c801c

Please sign in to comment.