From 210cfed25c73c15aa287e7b84662a53b48bf0a2f Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Tue, 6 May 2025 15:06:01 -0400 Subject: [PATCH 1/4] added in the tests --- DESCRIPTION | 4 ++-- R/use_stepcount_condaenv.R | 4 ++++ R/zzz.R | 3 +++ tests/testthat.R | 6 +----- 4 files changed, 10 insertions(+), 7 deletions(-) create mode 100644 R/zzz.R diff --git a/DESCRIPTION b/DESCRIPTION index 7e27f45..372fced 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: stepcount Title: Estimate Step Counts from 'Accelerometry' Data -Version: 0.3.3 +Version: 0.4.0 Authors@R: person(given = "John", family = "Muschelli", @@ -20,7 +20,7 @@ Imports: lubridate, magrittr, readr, - reticulate + reticulate (>= 1.42.0) Suggests: tidyr, dplyr, diff --git a/R/use_stepcount_condaenv.R b/R/use_stepcount_condaenv.R index 09bd3fb..6dcdd51 100644 --- a/R/use_stepcount_condaenv.R +++ b/R/use_stepcount_condaenv.R @@ -7,6 +7,7 @@ #' @export #' @rdname use_stepcount_condaenv use_stepcount_condaenv = function(envname = "stepcount", ...) { + .Deprecated('reticulate::py_require("stepcount")') reticulate_python = Sys.getenv("RETICULATE_PYTHON", unset = NA) if (!is.na(reticulate_python)) { warning( @@ -32,6 +33,8 @@ conda_create_stepcount = function( ..., python_version = "3.9" ) { + .Deprecated('reticulate::py_require("stepcount")') + reticulate::conda_create( envname = envname, packages = c("openjdk", "pip"), @@ -55,5 +58,6 @@ unset_reticulate_python = function() { #' @export #' @rdname use_stepcount_condaenv have_stepcount_condaenv = function() { + .Deprecated('reticulate::py_require("stepcount")') reticulate::condaenv_exists("stepcount") } diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..2aedf1d --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,3 @@ +.onLoad <- function(libname, pkgname) { + reticulate::py_require("stepcount", python_version = "3.10") +} diff --git a/tests/testthat.R b/tests/testthat.R index c320e1d..4753076 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -7,13 +7,9 @@ # * https://testthat.r-lib.org/articles/special-files.html +Sys.setenv("RETICULATE_PYTHON" = "managed") library(testthat) library(stepcount) -if (stepcount::have_stepcount_condaenv()) { - stepcount::unset_reticulate_python() - stepcount::use_stepcount_condaenv() -} - testthat::test_check("stepcount") From d92758675f09267de1161e44fae6812a1bb5e9b9 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Fri, 23 May 2025 12:32:22 -0400 Subject: [PATCH 2/4] new passes --- NAMESPACE | 5 --- R/install_stepcount.R | 22 ++---------- R/use_stepcount_condaenv.R | 63 ----------------------------------- man/stepcount_setup.Rd | 19 +++-------- man/use_stepcount_condaenv.Rd | 31 ----------------- tests/testthat.R | 4 --- 6 files changed, 6 insertions(+), 138 deletions(-) delete mode 100644 R/use_stepcount_condaenv.R delete mode 100644 man/use_stepcount_condaenv.Rd diff --git a/NAMESPACE b/NAMESPACE index 0d29cee..c9365b3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,10 +1,7 @@ # Generated by roxygen2: do not edit by hand export("%>%") -export(conda_create_stepcount) export(have_stepcount) -export(have_stepcount_condaenv) -export(install_stepcount) export(sc_download_model) export(sc_load_model) export(sc_model_filename) @@ -16,6 +13,4 @@ export(stepcount) export(stepcount_check) export(stepcount_version) export(stepcount_with_model) -export(unset_reticulate_python) -export(use_stepcount_condaenv) importFrom(magrittr,"%>%") diff --git a/R/install_stepcount.R b/R/install_stepcount.R index d0d906a..2d9d54c 100644 --- a/R/install_stepcount.R +++ b/R/install_stepcount.R @@ -1,30 +1,13 @@ -#' Install the `stepcount` Python Module +#' Check the `stepcount` Python Module #' -#' @param packages packages to install. -#' If `stepcount` is not included, it will be added. This package is -#' known to work with `stepcount==3.2.4` -#' @param ... Additional arguments to pass to [reticulate::py_install()], -#' other than `pip` (`pip = TRUE` enforced) #' -#' @return Output of [reticulate::py_install] +#' @return A logical value indicating whether the `stepcount` Python module is available. #' @export #' @rdname stepcount_setup #' @examples #' if (have_stepcount()) { #' stepcount_version() #' } -install_stepcount = function(packages = "stepcount", - ...) { - if (!any(grepl("^stepcount", trimws(tolower(packages))))) { - packages = unique(c(packages, "stepcount")) - } - reticulate::py_install( - packages = packages, - pip = TRUE, ...) -} - -#' @export -#' @rdname stepcount_setup have_stepcount = function() { reticulate::py_module_available("stepcount") } @@ -55,4 +38,3 @@ module_version = function(module = "numpy") { stepcount_version = function() { module_version("stepcount") } - diff --git a/R/use_stepcount_condaenv.R b/R/use_stepcount_condaenv.R deleted file mode 100644 index 6dcdd51..0000000 --- a/R/use_stepcount_condaenv.R +++ /dev/null @@ -1,63 +0,0 @@ -#' Use Conda Environment for `stepcount` -#' -#' @param ... additional arguments to pass to [reticulate::use_condaenv()] -#' other than `condaenv`. -#' -#' @return Nothing -#' @export -#' @rdname use_stepcount_condaenv -use_stepcount_condaenv = function(envname = "stepcount", ...) { - .Deprecated('reticulate::py_require("stepcount")') - reticulate_python = Sys.getenv("RETICULATE_PYTHON", unset = NA) - if (!is.na(reticulate_python)) { - warning( - paste0( - "[stepcount] RETICULATE_PYTHON environment variable is set, ", - "may not work. ", - 'Restart R, run Sys.unsetenv("RETICULATE_PYTHON") before running,', - "or run stepcount::unset_reticulate_python()") - ) - } - # if (!have_stepcount_condaenv()) { - # warning("stepcount conda environment does not seem to exist!") - # } - reticulate::use_condaenv(condaenv = envname, ...) -} - -#' @export -#' @rdname use_stepcount_condaenv -#' @param python_version version of Python to use for environment -#' @param envname environment name for the conda environment -conda_create_stepcount = function( - envname = "stepcount", - ..., - python_version = "3.9" -) { - .Deprecated('reticulate::py_require("stepcount")') - - reticulate::conda_create( - envname = envname, - packages = c("openjdk", "pip"), - python_version = python_version) - reticulate::py_install( - packages = "stepcount", - envname = envname, - python_version = python_version, - pip = TRUE, - ...) - -} - - -#' @export -#' @rdname use_stepcount_condaenv -unset_reticulate_python = function() { - Sys.unsetenv("RETICULATE_PYTHON") -} - -#' @export -#' @rdname use_stepcount_condaenv -have_stepcount_condaenv = function() { - .Deprecated('reticulate::py_require("stepcount")') - reticulate::condaenv_exists("stepcount") -} diff --git a/man/stepcount_setup.Rd b/man/stepcount_setup.Rd index c902e6e..4ed2e40 100644 --- a/man/stepcount_setup.Rd +++ b/man/stepcount_setup.Rd @@ -1,33 +1,22 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/install_stepcount.R -\name{install_stepcount} -\alias{install_stepcount} +\name{have_stepcount} \alias{have_stepcount} \alias{stepcount_check} \alias{stepcount_version} -\title{Install the \code{stepcount} Python Module} +\title{Check the \code{stepcount} Python Module} \usage{ -install_stepcount(packages = "stepcount", ...) - have_stepcount() stepcount_check() stepcount_version() } -\arguments{ -\item{packages}{packages to install. -If \code{stepcount} is not included, it will be added. This package is -known to work with \verb{stepcount==3.2.4}} - -\item{...}{Additional arguments to pass to \code{\link[reticulate:py_install]{reticulate::py_install()}}, -other than \code{pip} (\code{pip = TRUE} enforced)} -} \value{ -Output of \link[reticulate:py_install]{reticulate::py_install} +A logical value indicating whether the \code{stepcount} Python module is available. } \description{ -Install the \code{stepcount} Python Module +Check the \code{stepcount} Python Module } \examples{ if (have_stepcount()) { diff --git a/man/use_stepcount_condaenv.Rd b/man/use_stepcount_condaenv.Rd deleted file mode 100644 index fa8a691..0000000 --- a/man/use_stepcount_condaenv.Rd +++ /dev/null @@ -1,31 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/use_stepcount_condaenv.R -\name{use_stepcount_condaenv} -\alias{use_stepcount_condaenv} -\alias{conda_create_stepcount} -\alias{unset_reticulate_python} -\alias{have_stepcount_condaenv} -\title{Use Conda Environment for \code{stepcount}} -\usage{ -use_stepcount_condaenv(envname = "stepcount", ...) - -conda_create_stepcount(envname = "stepcount", ..., python_version = "3.9") - -unset_reticulate_python() - -have_stepcount_condaenv() -} -\arguments{ -\item{envname}{environment name for the conda environment} - -\item{...}{additional arguments to pass to \code{\link[reticulate:use_python]{reticulate::use_condaenv()}} -other than \code{condaenv}.} - -\item{python_version}{version of Python to use for environment} -} -\value{ -Nothing -} -\description{ -Use Conda Environment for \code{stepcount} -} diff --git a/tests/testthat.R b/tests/testthat.R index 4753076..deca649 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -5,11 +5,7 @@ # Learn more about the roles of various files in: # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview # * https://testthat.r-lib.org/articles/special-files.html - - -Sys.setenv("RETICULATE_PYTHON" = "managed") library(testthat) library(stepcount) - testthat::test_check("stepcount") From 679c93f3dfcdf5ab6eb957405df07d3f0ef8b6fb Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Fri, 23 May 2025 12:32:44 -0400 Subject: [PATCH 3/4] new rcmd check --- .github/workflows/R-CMD-check.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 2f935dc..28988ad 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -43,20 +43,6 @@ jobs: extra-packages: any::rcmdcheck needs: check - - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: stepcount - python-version: 3.9 - - - name: Conda info - shell: bash -el {0} - run: conda info - - - name: Pip install stepcount - shell: bash -el {0} - run: pip install stepcount - # run: pip install stepcount - - uses: r-lib/actions/check-r-package@v2 with: upload-snapshots: true From b34fd167feb4401ccb97b1af2713d72e71ea62a3 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Fri, 23 May 2025 12:33:34 -0400 Subject: [PATCH 4/4] test coverage no install stepcount --- .github/workflows/test-coverage.yaml | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index bb1b4f5..0ab748d 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -27,20 +27,6 @@ jobs: extra-packages: any::covr, any::xml2 needs: coverage - - uses: conda-incubator/setup-miniconda@v3 - with: - activate-environment: stepcount - python-version: 3.9 - - - name: Conda info - shell: bash -el {0} - run: conda info - - - name: Pip install stepcount - shell: bash -el {0} - run: pip install stepcount - # run: pip install stepcount - - name: Test coverage run: | cov <- covr::package_coverage(