Skip to content

Instantly share code, notes, and snippets.

@multimeric
Last active April 17, 2024 05:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save multimeric/f9ea6e2daea65053f43ea802dc3dfc0d to your computer and use it in GitHub Desktop.
Save multimeric/f9ea6e2daea65053f43ea802dc3dfc0d to your computer and use it in GitHub Desktop.
#' 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