Skip to content

Commit

Permalink
lint R
Browse files Browse the repository at this point in the history
  • Loading branch information
scottgigante committed Mar 10, 2021
1 parent 1130d1e commit 9f2d13a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
22 changes: 17 additions & 5 deletions Rmagic/R/magic.R
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ magic.default <- function(
k = NULL, alpha = NULL,
...) {
# check installation
if (!reticulate::py_module_available(module = "magic") || (is.null(pymagic))) load_pymagic()
if (!reticulate::py_module_available(module = "magic") ||
(is.null(pymagic))) load_pymagic()
# check for deprecated arguments
if (!is.null(k)) {
message("Argument k is deprecated. Using knn instead.")
Expand Down Expand Up @@ -160,7 +161,11 @@ magic.default <- function(
} else {
# character vector
if (!all(genes %in% colnames(x = data))) {
warning(paste0("Genes ", genes[!(genes %in% colnames(data))], " not found.", collapse = ", "))
warning(paste0(
"Genes ",
genes[!(genes %in% colnames(data))],
" not found.",
collapse = ", "))
}
genes <- which(x = colnames(x = data) %in% genes)
gene_names <- colnames(x = data)[genes]
Expand Down Expand Up @@ -338,10 +343,17 @@ magic.Seurat <- function(
...
)
assay_name <- paste0("MAGIC_", assay)
data[[assay_name]] <- Seurat::CreateAssayObject(data = t(x = as.matrix(x = results$result)))
data[[assay_name]] <- Seurat::CreateAssayObject(
data = t(x = as.matrix(x = results$result))
)
print(paste0(
"Added MAGIC output to ", assay_name, ". To use it, pass assay='", assay_name,
"' to downstream methods or set DefaultAssay(seurat_object) <- '", assay_name, "'."
"Added MAGIC output to ",
assay_name,
". To use it, pass assay='",
assay_name,
"' to downstream methods or set DefaultAssay(seurat_object) <- '",
assay_name,
"'."
))
Seurat::Tool(object = data) <- results[c("operator", "params")]
return(data)
Expand Down
32 changes: 22 additions & 10 deletions Rmagic/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,30 @@ check_pymagic_version <- function() {
minor_version <- as.integer(rversion[2])
if (as.integer(pyversion[1]) < major_version) {
warning(paste0(
"Python MAGIC version ", pymagic$`__version__`, " is out of date (recommended: ",
major_version, ".", minor_version, "). Please update with pip ",
"(e.g. ", reticulate::py_config()$python, " -m pip install --upgrade magic-impute) or Rmagic::install.magic()."
"Python MAGIC version ",
pymagic$`__version__`,
" is out of date (recommended: ",
major_version,
".",
minor_version,
"). Please update with pip ",
"(e.g. ",
reticulate::py_config()$python,
" -m pip install --upgrade magic-impute) or Rmagic::install.magic()."
))
return(FALSE)
} else if (as.integer(pyversion[2]) < minor_version) {
warning(paste0(
"Python MAGIC version ", pymagic$`__version__`, " is out of date (recommended: ",
major_version, ".", minor_version, "). Consider updating with pip ",
"(e.g. ", reticulate::py_config()$python, " -m pip install --upgrade magic-impute) or Rmagic::install.magic()."
"Python MAGIC version ",
pymagic$`__version__`,
" is out of date (recommended: ",
major_version,
".",
minor_version,
"). Consider updating with pip ",
"(e.g. ",
reticulate::py_config()$python,
" -m pip install --upgrade magic-impute) or Rmagic::install.magic()."
))
return(FALSE)
}
Expand Down Expand Up @@ -77,8 +91,7 @@ load_pymagic <- function() {
#'
#' @export
pymagic_is_available <- function() {
tryCatch(
{
tryCatch( {
reticulate::import("magic")$MAGIC
check_pymagic_version()
},
Expand Down Expand Up @@ -111,8 +124,7 @@ pymagic_is_available <- function() {
install.magic <- function(envname = "r-reticulate", method = "auto",
conda = "auto", pip = TRUE, ...) {
message("Attempting to install MAGIC python package with reticulate")
tryCatch(
{
tryCatch( {
reticulate::py_install("magic-impute",
envname = envname, method = method,
conda = conda, pip = pip, ...
Expand Down

0 comments on commit 9f2d13a

Please sign in to comment.