From 6e66dfb3d736af0140c7a9bdb3da95127eadf040 Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Fri, 23 May 2025 11:55:15 -0400 Subject: [PATCH 1/2] Add NEWS.md --- NEWS.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 NEWS.md diff --git a/NEWS.md b/NEWS.md new file mode 100644 index 0000000..a9f3c13 --- /dev/null +++ b/NEWS.md @@ -0,0 +1,5 @@ +# walking 0.4.0 + +* New `reticulate` initialization. +* Removing `install_forest` and the like. +* Initial CRAN submission. From 757c209cba006431a642196c2153df9a9ee9a83b Mon Sep 17 00:00:00 2001 From: muschellij2 Date: Fri, 23 May 2025 12:01:03 -0400 Subject: [PATCH 2/2] added new reticulate that now simplifies thing sgreatly --- .github/workflows/R-CMD-check.yaml | 8 +-- DESCRIPTION | 6 +-- NAMESPACE | 5 -- R/api.R | 2 +- R/find_walking.R | 2 +- R/install_forest.R | 80 ------------------------------ R/sdt.R | 3 +- R/verisense_count_steps.R | 2 +- R/zzz.R | 9 ++++ man/estimate_steps.Rd | 2 +- man/find_walking.Rd | 2 +- man/forest_setup.Rd | 40 --------------- man/verisense_count_steps.Rd | 2 +- tests/testthat.R | 5 ++ walking.Rproj | 1 + 15 files changed, 30 insertions(+), 139 deletions(-) delete mode 100644 R/install_forest.R create mode 100644 R/zzz.R delete mode 100644 man/forest_setup.Rd diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index c2a61d8..945050f 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -29,10 +29,10 @@ jobs: - uses: actions/setup-python@v4 if: matrix.config.python != 'debug' with: - python-version: 3.9 + python-version: 3.11 - - name: setup forest - run: | - pip install git+https://github.com/onnela-lab/forest@develop + # - name: setup forest + # run: | + # pip install git+https://github.com/onnela-lab/forest@45fb41038bd46c25d9e6a4442aa74fa03b501317 - uses: r-lib/actions/check-r-package@v2 diff --git a/DESCRIPTION b/DESCRIPTION index ff99ee8..4264d12 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: walking Title: Segments Accelerometry Data into Walking using the Python `forest` Module -Version: 0.3.2 +Version: 0.4.0 Authors@R: person(given = "John", family = "Muschelli", @@ -13,14 +13,14 @@ Description: Interfaces the `forest` Python License: GPL (>= 3) Encoding: UTF-8 Roxygen: list(markdown = TRUE) -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Imports: assertthat, dplyr, lubridate, magrittr, matrixStats, - reticulate, + reticulate (>= 1.4.1), signal, tidyr Suggests: diff --git a/NAMESPACE b/NAMESPACE index e76d7c1..0b21e97 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -5,11 +5,6 @@ export(estimate_steps_forest) export(estimate_steps_sdt) export(estimate_steps_verisense) export(find_walking) -export(forest_requirement) -export(forest_version) -export(forest_version_pip) -export(have_forest) -export(install_forest) export(preprocess_bout) export(preprocess_bout_r) export(resample_accel_data) diff --git a/R/api.R b/R/api.R index b28ea3d..2026d42 100644 --- a/R/api.R +++ b/R/api.R @@ -10,7 +10,7 @@ #' @rdname estimate_steps #' @examples #' csv_file = system.file("test_data_bout.csv", package = "walking") -#' if (requireNamespace("readr", quietly = TRUE) && walking::have_forest()) { +#' if (requireNamespace("readr", quietly = TRUE)) { #' x = readr::read_csv(csv_file) #' colnames(x)[colnames(x) == "UTC time"] = "time" #' out = estimate_steps_forest(x, sample_rate_analysis = 10L) diff --git a/R/find_walking.R b/R/find_walking.R index 4c855c8..625e9ee 100644 --- a/R/find_walking.R +++ b/R/find_walking.R @@ -27,7 +27,7 @@ #' #' @examples #' csv_file = system.file("test_data_bout.csv", package = "walking") -#' if (requireNamespace("readr", quietly = TRUE) && walking::have_forest()) { +#' if (requireNamespace("readr", quietly = TRUE)) { #' x = readr::read_csv(csv_file) #' colnames(x)[colnames(x) == "UTC time"] = "time" #' res = find_walking(data = x) diff --git a/R/install_forest.R b/R/install_forest.R deleted file mode 100644 index 83f4eba..0000000 --- a/R/install_forest.R +++ /dev/null @@ -1,80 +0,0 @@ -#' Install the `forest` Python Module -#' -#' @param ref Git reference to install, default is `main`. Use `develop` for -#' the current development branch on GitHub. -#' @param ... Additional arguments to pass to [reticulate::py_install()], -#' other than `pip` (`pip = TRUE` enforced) -#' -#' @return Output of [reticulate::py_install] -#' @export -#' @rdname forest_setup -#' @examples -#' if (have_forest()) { -#' forest_version() -#' forest_version_pip() -#' } -#' -install_forest = function(ref = "develop", - ... -) { - url = "https://github.com/onnela-lab/forest" - url = paste0("git+", url) - ref = sub("^@", "", ref) - url = paste0(url, "@", ref) - reticulate::py_install( - url, - pip = TRUE, ...) -} - -#' @export -#' @rdname forest_setup -have_forest = function() { - reticulate::py_module_available("forest") -} - - -module_info = function(module = "numpy") { - assertthat::is.scalar(module) - if (!reticulate::py_module_available(module)) { - stop(paste0(module, " is not installed!")) - } - df = reticulate::py_list_packages() - df[df$package == module,] -} - -module_version = function(module = "numpy") { - module_info(module = module)$version -} - -module_requirement = function(module = "numpy") { - module_info(module = module)$requirement -} - -#' @export -#' @rdname forest_setup -forest_version = function() { - module_version("forest") -} - -module_version_pip = function(module = "numpy") { - python = reticulate::py_config()$python - python = shQuote(python) - cmd = paste0(python, " -m pip freeze") - out = system(cmd, intern = TRUE) - out = out[grep(paste0("^", module, "(=|\\s|@)"), out)] - out -} - -#' @export -#' @rdname forest_setup -forest_version_pip = function() { - module_version_pip("forest") - -} - -#' @export -#' @rdname forest_setup -forest_requirement = function() { - module_requirement("forest") -} - diff --git a/R/sdt.R b/R/sdt.R index 0891e35..43d439e 100644 --- a/R/sdt.R +++ b/R/sdt.R @@ -34,7 +34,8 @@ sdt_count_steps <- function( rm(list = c("vm", "X", "Y", "Z", "demean_vm", "filt_vm", "peak", "HEADER_TIMESTAMP")) location = match.arg(location, choices = c("wrist", "waist")) - threshold = ifelse(location == "wrist", 0.0267, 0.0359) + # fixed thresholds for wrist and waist May23, 2025 + threshold = ifelse(location == "wrist", 0.0359, 0.0267) data = standardize_data(data, subset = TRUE) assertthat::assert_that( diff --git a/R/verisense_count_steps.R b/R/verisense_count_steps.R index 3c1df4f..7578ebe 100644 --- a/R/verisense_count_steps.R +++ b/R/verisense_count_steps.R @@ -183,7 +183,7 @@ create_peak_info = function(segments) { #' #' @examples #' csv_file = system.file("test_data_bout.csv", package = "walking") -#' if (requireNamespace("readr", quietly = TRUE) && walking::have_forest()) { +#' if (requireNamespace("readr", quietly = TRUE)) { #' x = readr::read_csv(csv_file) #' colnames(x)[colnames(x) == "UTC time"] = "time" #' out = verisense_count_steps(x, sample_rate = 10L) diff --git a/R/zzz.R b/R/zzz.R new file mode 100644 index 0000000..ffa6264 --- /dev/null +++ b/R/zzz.R @@ -0,0 +1,9 @@ +.onLoad <- function(...) { + # ref = "v0.2" + ref = "45fb41038bd46c25d9e6a4442aa74fa03b501317" + url = "https://github.com/onnela-lab/forest" + url = paste0("git+", url) + ref = sub("^@", "", ref) + url = paste0(url, "@", ref) + reticulate::py_require(url, python_version = "3.11") +} diff --git a/man/estimate_steps.Rd b/man/estimate_steps.Rd index f184917..b78f0e6 100644 --- a/man/estimate_steps.Rd +++ b/man/estimate_steps.Rd @@ -37,7 +37,7 @@ Estimate Steps with Unified Syntax } \examples{ csv_file = system.file("test_data_bout.csv", package = "walking") -if (requireNamespace("readr", quietly = TRUE) && walking::have_forest()) { +if (requireNamespace("readr", quietly = TRUE)) { x = readr::read_csv(csv_file) colnames(x)[colnames(x) == "UTC time"] = "time" out = estimate_steps_forest(x, sample_rate_analysis = 10L) diff --git a/man/find_walking.Rd b/man/find_walking.Rd index 088bac2..a042b46 100644 --- a/man/find_walking.Rd +++ b/man/find_walking.Rd @@ -51,7 +51,7 @@ Frequency components are extracted with Continuous Wavelet Transform. } \examples{ csv_file = system.file("test_data_bout.csv", package = "walking") -if (requireNamespace("readr", quietly = TRUE) && walking::have_forest()) { +if (requireNamespace("readr", quietly = TRUE)) { x = readr::read_csv(csv_file) colnames(x)[colnames(x) == "UTC time"] = "time" res = find_walking(data = x) diff --git a/man/forest_setup.Rd b/man/forest_setup.Rd deleted file mode 100644 index 72e2d4a..0000000 --- a/man/forest_setup.Rd +++ /dev/null @@ -1,40 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/install_forest.R -\name{install_forest} -\alias{install_forest} -\alias{have_forest} -\alias{forest_version} -\alias{forest_version_pip} -\alias{forest_requirement} -\title{Install the \code{forest} Python Module} -\usage{ -install_forest(ref = "develop", ...) - -have_forest() - -forest_version() - -forest_version_pip() - -forest_requirement() -} -\arguments{ -\item{ref}{Git reference to install, default is \code{main}. Use \code{develop} for -the current development branch on GitHub.} - -\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} -} -\description{ -Install the \code{forest} Python Module -} -\examples{ -if (have_forest()) { - forest_version() - forest_version_pip() -} - -} diff --git a/man/verisense_count_steps.Rd b/man/verisense_count_steps.Rd index 218ff0d..aef19e9 100644 --- a/man/verisense_count_steps.Rd +++ b/man/verisense_count_steps.Rd @@ -82,7 +82,7 @@ for the parameters as based on \url{doi:10.3390/s22249984}. } \examples{ csv_file = system.file("test_data_bout.csv", package = "walking") -if (requireNamespace("readr", quietly = TRUE) && walking::have_forest()) { +if (requireNamespace("readr", quietly = TRUE)) { x = readr::read_csv(csv_file) colnames(x)[colnames(x) == "UTC time"] = "time" out = verisense_count_steps(x, sample_rate = 10L) diff --git a/tests/testthat.R b/tests/testthat.R index 1b57353..fad7dff 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -9,4 +9,9 @@ library(testthat) library(walking) +# if (walking::have_walking_condaenv()) { +# walking::unset_reticulate_python() +# walking::use_walking_condaenv() +# } + test_check("walking") diff --git a/walking.Rproj b/walking.Rproj index eee5b6f..4193714 100644 --- a/walking.Rproj +++ b/walking.Rproj @@ -1,4 +1,5 @@ Version: 1.0 +ProjectId: 61f5e877-0e4c-49c6-8d46-f348ca15f168 RestoreWorkspace: No SaveWorkspace: No