Skip to content

Commit

Permalink
added install package functions
Browse files Browse the repository at this point in the history
  • Loading branch information
dipterix committed Mar 15, 2024
1 parent 0405a5e commit 4f0c857
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: ravemanager
Title: Manage 'RAVE' Packages
Version: 1.0.39
Version: 1.0.40
Authors@R:
person("Zhengjia", "Wang", email = "[email protected]",
role = c("aut", "cre"))
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

S3method(print,ravemanager_cmd)
S3method(print,ravemanager_printable)
export(add_py_package)
export(add_r_package)
export(add_shortcuts)
export(clear_cache)
export(configure_python)
Expand Down
63 changes: 63 additions & 0 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -773,3 +773,66 @@ uninstall <- function(components = c("cache", "python", "all")) {
message(msg)
}
}

#' @name install_packages
#' @title Install/Update R or Python packages to RAVE environment
#' @param pkg name of the package
#' @param method whether to use \code{'pip'} or \code{'conda'}; default is
#' \code{'pip'}
#' @param repos,lib,type,INSTALL_opts,... internally used
#' @returns Nothing
#'
#' @examples
#' \dontrun{
#'
#'
#' # ---- R --------------------------------------------------------
#' # Install R packages (CRAN, BioC, or RAVE's repository)
#' add_r_package("ravebuiltins")
#' add_r_package("rhdf5")
#'
#' # Install from Github (github.com/dipterix/threeBrain)
#' add_r_package("dipterix/threeBrain")
#'
#' # Install Github branch
#' add_r_package("dipterix/threeBrain@custom-electrode-geom")
#'
#' # ---- Python ----------------------------------------------------
#'
#' # Normal pypi packages
#' add_py_package("threebrainpy")
#'
#' # Add through conda
#' add_py_package("fftw", method = "conda")
#'
#'
#' }
#'
#'
#' @export
add_r_package <- function(pkg, lib = get_libpaths(check = TRUE),
repos = get_mirror(), type = getOption("pkgType"),
..., INSTALL_opts = '--no-lock') {
if( system.file(package = "pak") == "" ) {
utils::install.packages("pak", repos = repos, lib = lib, type = type, INSTALL_opts = INSTALL_opts)
}
pak <- asNamespace("pak")
current_repos <- pak$repo_get(bioc = FALSE)
repos[current_repos$name] <- current_repos$url
options(repos = repos)
pak$pkg_install(pkg = pkg, lib = lib, upgrade = TRUE, ask = FALSE, dependencies = NA)
return(invisible())
}

#' @rdname install_packages
#' @export
add_py_package <- function(pkg, method = c("pip", "conda")) {
method <- match.arg(method)
rpymat <- asNamespace("rpymat")
if( method == 'pip' ) {
rpymat$add_packages(pkg, pip = TRUE)
} else {
rpymat$add_packages(pkg)
}
return(invisible())
}
61 changes: 61 additions & 0 deletions man/install_packages.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4f0c857

Please sign in to comment.