Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚸 Check attaching to environment in install_lamindb() #135

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 30 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,34 @@ 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, ...)

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

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)
}
Loading