| 19 | |
| 20 | However, sometimes Seurat may depend on other R packages to run certain functions, in that case, only loading the older version of Seurat may not work. Instead, we could explicitly load all R packages from the last R library set to keep the packages compatible. |
| 21 | {{{ |
| 22 | set_lib_paths <- function(lib_vec) { |
| 23 | lib_vec <- normalizePath(lib_vec, mustWork = TRUE) |
| 24 | shim_fun <- .libPaths |
| 25 | shim_env <- new.env(parent = environment(shim_fun)) |
| 26 | shim_env$.Library <- character() |
| 27 | shim_env$.Library.site <- character() |
| 28 | environment(shim_fun) <- shim_env |
| 29 | shim_fun(lib_vec) |
| 30 | } |
| 31 | |
| 32 | set_lib_paths(c("/nfs/apps/lib/R/4.2-focal/site-library.2023q1", "/opt/R/4.2.1/lib/R/library")) |
| 33 | |
| 34 | library(Seurat) |
| 35 | # load other required packages, e.g. scPred, for cell type annotation. |
| 36 | library(scPred) |
| 37 | }}} |
| 38 | |
| 39 | By running the codes above, all the required R packages will be loaded from the previous R library set (2023q1). |