From fd29aef4b210fb0d47e535b48b7308cc440ed089 Mon Sep 17 00:00:00 2001 From: aviezerl Date: Tue, 7 May 2024 16:48:46 +0300 Subject: [PATCH] fix: `emr_track.mv` did not move track attributes. fixes emr_track.mv does not copy track attributes #119 --- DESCRIPTION | 4 ++-- NEWS.md | 4 ++++ R/track-attributes.R | 2 -- R/track.R | 9 +++++++++ man/naryn-package.Rd | 25 +++++++++++++++++++++++++ tests/testthat/test-track.create.R | 22 ++++++++++++++++++++++ 6 files changed, 62 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bdd04716..09c126f2 100755 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: naryn Title: Native Access Medical Record Retriever for High Yield Analytics -Version: 2.6.27 +Version: 2.6.28 Authors@R: c( person("Misha", "Hoichman", , "misha@hoichman.com", role = "aut"), person("Aviezer", "Lifshitz", , "aviezer.lifshitz@weizmann.ac.il", role = c("aut", "cre")), @@ -54,4 +54,4 @@ Language: en-US LazyLoad: yes NeedsCompilation: yes OS_type: unix -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NEWS.md b/NEWS.md index 3650b630..5cdc918f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# naryn 2.6.28 + +* Fix: `emr_track.mv` did not move track attributes. + # naryn 2.6.27 * Fix: do not truncate expression names in `emr_extract` when `tidy=TRUE`. diff --git a/R/track-attributes.R b/R/track-attributes.R index c187940b..91158df6 100644 --- a/R/track-attributes.R +++ b/R/track-attributes.R @@ -83,8 +83,6 @@ emr_track.attr.export <- function(track = NULL, attr = NULL, include_missing = F return(res) } - - #' Returns the value of the track attribute #' #' Returns the value of the track attribute. diff --git a/R/track.R b/R/track.R index b2c9f5a5..45eb6af7 100644 --- a/R/track.R +++ b/R/track.R @@ -670,6 +670,8 @@ emr_track.mv <- function(src, tgt, space = NULL) { stop(sprintf("Filter %s already exists", tgt), call. = FALSE) } + attrs <- emr_track.attr.export(src) + if (emr_track.logical.exists(src)) { ltrack <- emr_track.logical.info(src) emr_track.logical.rm(src, force = TRUE) @@ -702,6 +704,13 @@ emr_track.mv <- function(src, tgt, space = NULL) { if (file.exists(dirname2)) { .emr_dir.mv(dirname2, .emr_track.pyvar.dir(tgt)) } + + # if track has atributes - move them as well + if (nrow(attrs) > 0) { + purrr::walk2(attrs$attr, attrs$value, ~ { + emr_track.attr.set(tgt, .x, .y) + }) + } } diff --git a/man/naryn-package.Rd b/man/naryn-package.Rd index e47dbb96..97d5a3b4 100644 --- a/man/naryn-package.Rd +++ b/man/naryn-package.Rd @@ -14,5 +14,30 @@ For a complete list of help resources, use \code{library(help = "naryn")}. More information about the options can be found in 'User manual' of the package. +} +\seealso{ +Useful links: +\itemize{ + \item \url{https://tanaylab.github.io/naryn/} + \item Report bugs at \url{https://github.com/tanaylab/naryn/issues} +} + +} +\author{ +\strong{Maintainer}: Aviezer Lifshitz \email{aviezer.lifshitz@weizmann.ac.il} + +Authors: +\itemize{ + \item Misha Hoichman \email{misha@hoichman.com} + \item Ben Gilat \email{ben.gilat@weizmann.ac.il} +} + +Other contributors: +\itemize{ + \item Netta Mendelson-Cohen \email{Netta.Mendelsoncohen@weizmann.ac.il} [contributor] + \item Rami Jaschek \email{rami.jaschek@weizmann.ac.il} [contributor] + \item Weizmann Institute of Science [copyright holder] +} + } \keyword{package} diff --git a/tests/testthat/test-track.create.R b/tests/testthat/test-track.create.R index 52fe6864..557c98be 100644 --- a/tests/testthat/test-track.create.R +++ b/tests/testthat/test-track.create.R @@ -102,6 +102,28 @@ test_that("emr_track.mv works with different values", { withr::defer(emr_track.rm("test_track2", TRUE)) }) +test_that("emr_track.mv moves track attribues as well", { + emr_track.rm("test_track1", TRUE) + emr_track.create("test_track1", "user", FALSE, "track0+2", keepref = FALSE) + emr_track.attr.set("test_track1", "test_attr", "value") + emr_track.mv("test_track1", "test_track2") + expect_false(emr_track.exists("test_track1")) + expect_true(emr_track.exists("test_track2")) + expect_equal(emr_track.attr.get("test_track2", "test_attr"), "value") + withr::defer(emr_track.rm("test_track2", TRUE)) +}) + +test_that("emr_track.mv moves track vars as well", { + emr_track.rm("test_track1", TRUE) + emr_track.create("test_track1", "user", FALSE, "track0+2", keepref = FALSE) + emr_track.var.set("test_track1", "test_var", 1:10) + emr_track.mv("test_track1", "test_track2") + expect_false(emr_track.exists("test_track1")) + expect_true(emr_track.exists("test_track2")) + expect_equal(emr_track.var.get("test_track2", "test_var"), 1:10) + withr::defer(emr_track.rm("test_track2", TRUE)) +}) + test_that("emr_track.rm doesn't fail when given character(0)", { emr_track.rm(character(0)) expect_true(TRUE)