#' 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="+=" ) ) }