Skip to content

Commit

Permalink
more informative error on install
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Jul 13, 2018
1 parent be5c9f1 commit 6cd0aaf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions Rmagic/R/magic.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#' Perform MAGIC on a data matrix
#'
#'
#' Markov Affinity-based Graph Imputation of Cells (MAGIC) is an
#' algorithm for denoising and transcript recover of single cells
#' applied to single-cell RNA sequencing data, as described in
Expand Down Expand Up @@ -83,7 +83,7 @@ magic <- function(data,
seed=NULL) {
# check installation
if (!reticulate::py_module_available(module = "magic")) {
install.magic()
load_pymagic()
}
tryCatch(pymagic, error = function(e) load_pymagic())
k <- as.integer(k)
Expand Down
18 changes: 9 additions & 9 deletions Rmagic/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ null_equal <- function(x, y) {
}
}

load_pymagic <- function() {
pymagic <<- reticulate::import("magic", delay_load = TRUE)
load_pymagic <- function(delay_load = FALSE) {
result <- try(pymagic <<- reticulate::import("magic", delay_load = delay_load))
if (methods::is(result, "try-error")) {
install.magic()
}
}

#' Install PHATE Python Package
#' Install MAGIC Python Package
#'
#' Install PHATE Python package into a virtualenv or conda env.
#' Install MAGIC Python package into a virtualenv or conda env.
#'
#' On Linux and OS X the "virtualenv" method will be used by default
#' ("conda" will be used if virtualenv isn't available). On Windows,
#' the "conda" method is always used.
#' As of reticulate v1.7, this functionality is only available in the
#' development version of reticulate, which can be installed using
#' `devtools::install_github('rstudio/reticulate')`
#'
#' @param envname Name of environment to install packages into
#' @param method Installation method. By default, "auto" automatically finds
Expand All @@ -39,13 +39,13 @@ load_pymagic <- function() {
install.magic <- function(envname = "r-reticulate", method = "auto",
conda = "auto", pip=TRUE, ...) {
stop(paste0(
"Cannot install MAGIC, please install from a console with ",
"Cannot locate MAGIC Python package, please install from a console with ",
"pip install --user git+git://github.com/KrishnaswamyLab/MAGIC.git#subdirectory=python"
))
}

pymagic <- NULL

.onLoad <- function(libname, pkgname) {
load_pymagic()
load_pymagic(delay_load = TRUE)
}

0 comments on commit 6cd0aaf

Please sign in to comment.