Last active
April 17, 2024 05:50
-
-
Save multimeric/f9ea6e2daea65053f43ea802dc3dfc0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#' Installs one or more packages using the libraries inside a conda environment | |
#' | |
#' @param packages A vector of package names to install. This is the same as the | |
#' argument you would normally pass to `install.packages` | |
#' @param env The path to the conda environment that already has the dependencies installed into it | |
install_using_conda <- function(packages, env){ | |
env <- normalizePath(env) | |
if (!"withr" %in% rownames(installed.packages())) install.packages("withr") | |
withr::with_envvar( | |
# Tell R where to find the pkgconfig | |
c(PKG_CONFIG_PATH = file.path(env, "lib/pkgconfig")), | |
withr::with_makevars( | |
# Tell R to bake the library path into the compiled library | |
c(LDFLAGS = paste0("-Wl,-rpath,", file.path(env, "lib"))), | |
utils::install.packages(packages, type = "source"), | |
assignment="+=" | |
) | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment