diff --git a/scprep/run/__init__.py b/scprep/run/__init__.py index d654d429..355e8930 100644 --- a/scprep/run/__init__.py +++ b/scprep/run/__init__.py @@ -1,5 +1,6 @@ from .dyngen import DyngenSimulate from .r_function import install_bioconductor +from .r_function import install_github from .r_function import RFunction from .slingshot import Slingshot from .splatter import SplatSimulate diff --git a/scprep/run/dyngen.py b/scprep/run/dyngen.py index 766b75ee..5ce52f0a 100644 --- a/scprep/run/dyngen.py +++ b/scprep/run/dyngen.py @@ -2,6 +2,17 @@ import pandas as pd +_install_dyngen = r_function.RFunction( + args="""lib=.libPaths()[1], dependencies=NA, + repos='http://cran.rstudio.com', verbose=TRUE""", + body=""" + install.packages(c("dynwrap", "dyngen"), + lib=lib, + repos=repos, + dependencies=dependencies) + """, +) + _get_backbones = r_function.RFunction( setup=""" library(dyngen) @@ -95,13 +106,10 @@ def install( lib=None, dependencies=None, - update=False, repos="http://cran.us.r-project.org", - build_vignettes=False, - force=False, verbose=True, ): - """Install Dyngen Github repository. + """Install Dyngen from CRAN. Parameters ---------- @@ -114,37 +122,22 @@ def install( When False, installs no dependencies. When None/NA, installs all packages specified under "Depends", "Imports" and "LinkingTo". - update: string or boolean, optional (default: False) - One of "default", "ask", "always", or "never". "default" - Respects R_REMOTES_UPGRADE variable if set, falls back to "ask" if unset. - "ask" prompts the user for which out of date packages to upgrade. - For non-interactive sessions "ask" is equivalent to "always". - TRUE and FALSE also accepted, correspond to "always" and "never" respectively. repos: string, optional (default: "http://cran.us.r-project.org"): R package repository. - build_vignettes: boolean, optional (default: False) - Builds Github vignettes. - force: boolean, optional (default: False) - Forces installation even if remote state has not changed since previous install. verbose: boolean, optional (default: True) Install script verbosity. """ - r_function.install_github( - repo="dynverse/dynwrap", - update=update, - lib=lib, - dependencies=dependencies, - repos=repos, - verbose=verbose, - ) - r_function.install_github( - repo="dynverse/dyngen", - update=update, - lib=lib, - dependencies=dependencies, + kwargs = {} + if lib is not None: + kwargs["lib"] = lib + if dependencies is not None: + kwargs["dependencies"] = dependencies + + _install_dyngen( repos=repos, verbose=verbose, + **kwargs, ) diff --git a/test/test_run.py b/test/test_run.py index e6f19e01..68e5da94 100644 --- a/test/test_run.py +++ b/test/test_run.py @@ -44,18 +44,18 @@ def test_install_bioc(): ) def test_install_github_lib(): - scprep.run.dyngen.install(verbose=False) + scprep.run.install_github("twitter/AnomalyDetection", verbose=False) fun = scprep.run.RFunction( body=""" packages <- installed.packages() - 'dyngen' %in% packages + 'AnomalyDetection' %in% packages """ ) assert fun() def test_install_github_dependencies_None(): - scprep.run.dyngen.install(verbose=False) + scprep.run.install_github("twitter/AnomalyDetection", verbose=False) fun = scprep.run.RFunction( body=""" if (!require("pacman", quietly=TRUE)) { @@ -63,7 +63,8 @@ def test_install_github_dependencies_None(): repos='http://cran.rstudio.com') } - deps <- pacman::p_depends(dyngen)[c("Depends","Imports","LinkingTo")] + deps <- pacman::p_depends(AnomalyDetection, local=TRUE)[c("Depends", + "Imports","LinkingTo")] all(unname(unlist(deps)) %in% installed.packages()[, "Package"]) """ ) @@ -71,7 +72,9 @@ def test_install_github_dependencies_None(): assert fun() def test_install_github_dependencies_True(): - scprep.run.dyngen.install(verbose=False, dependencies=True) + scprep.run.install_github( + "twitter/AnomalyDetection", verbose=False, dependencies=True + ) fun = scprep.run.RFunction( body=""" if (!require("pacman", quietly=TRUE)) { @@ -79,8 +82,8 @@ def test_install_github_dependencies_True(): repos='http://cran.rstudio.com') } - deps <- pacman::p_depends(dyngen)[c("Depends","Imports","LinkingTo", - "Suggests")] + deps <- pacman::p_depends(AnomalyDetection, local=TRUE)[c("Depends", + "Imports","LinkingTo","Suggests")] deps <- unname(unlist(deps)) installed <- installed.packages()[, "Package"] success <- all(deps %in% installed) @@ -294,6 +297,54 @@ class TestDyngen(unittest.TestCase): def setUpClass(self): scprep.run.dyngen.install(verbose=False) + def test_install_dyngen_lib(self): + scprep.run.dyngen.install(verbose=False) + fun = scprep.run.RFunction( + body=""" + packages <- installed.packages() + 'dyngen' %in% packages + """ + ) + + assert fun() + + def test_install_dyngen_dependencies_None(self): + scprep.run.dyngen.install(verbose=False) + fun = scprep.run.RFunction( + body=""" + if (!require("pacman", quietly=TRUE)) { + install.packages("pacman", + repos='http://cran.rstudio.com') + } + + deps <- pacman::p_depends(dyngen)[c("Depends","Imports","LinkingTo")] + all(unname(unlist(deps)) %in% installed.packages()[, "Package"]) + """ + ) + + assert fun() + + def test_install_dyngen_dependencies_True(self): + scprep.run.dyngen.install(verbose=False, dependencies=True) + fun = scprep.run.RFunction( + body=""" + if (!require("pacman", quietly=TRUE)) { + install.packages("pacman", + repos='http://cran.rstudio.com') + } + + deps <- pacman::p_depends(dyngen)[c("Depends","Imports","LinkingTo", + "Suggests")] + deps <- unname(unlist(deps)) + installed <- installed.packages()[, "Package"] + success <- all(deps %in% installed) + list(success=success, deps=deps, installed=installed) + """ + ) + + result = fun() + assert result["success"], result + def test_dyngen_backbone_not_in_list(self): utils.assert_raises_message( ValueError,