Skip to content

Commit

Permalink
include python update message
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Nov 24, 2018
1 parent 8712f8e commit 2aabea9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Rmagic/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,44 @@ null_equal <- function(x, y) {
}

load_pymagic <- function(delay_load = FALSE) {
# load
if (is.null(pymagic)) {
# first time load
result <- try(pymagic <<- reticulate::import("magic", delay_load = delay_load))
} else {
# already loaded
result <- try(reticulate::import("magic", delay_load = delay_load))
}
# check
if (methods::is(result, "try-error")) {
# failed load
if ((!delay_load) && length(grep("ModuleNotFoundError: No module named 'magic'", result)) > 0 ||
length(grep("ImportError: No module named magic", result)) > 0) {
# not installed
if (utils::menu(c("Yes", "No"), title="Install MAGIC Python package with reticulate?") == 1) {
install.magic()
}
} else if (length(grep("r\\-reticulate", reticulate::py_config()$python)) > 0) {
# installed, but envs sometimes give weird results
message("Consider removing the 'r-reticulate' environment by running:")
if (grep("virtualenvs", reticulate::py_config()$python)) {
message("reticulate::virtualenv_remove('r-reticulate')")
} else {
message("reticulate::conda_remove('r-reticulate')")
}
}
} else {
# successful load
version <- strsplit(pymagic$`__version__`, '\\.')[[1]]
major_version <- 1
minor_version <- 4
if (as.integer(version[1]) < major_version) {
stop(paste0("Python MAGIC version ", pymagic$`__version__`, " is out of date (recommended: ",
major_version, ".", minor_version, "). Please update with pip or Rmagic::install.magic()."))
} else if (as.integer(version[2]) < minor_version) {
warning(paste0("Python MAGIC version ", pymagic$`__version__`, " is out of date (recommended: ",
major_version, ".", minor_version, "). Consider updating with pip or Rmagic::install.magic()."))
}
}
}

Expand Down

0 comments on commit 2aabea9

Please sign in to comment.