Skip to content

Commit

Permalink
fix: emr_track.mv did not move track attributes.
Browse files Browse the repository at this point in the history
fixes emr_track.mv does not copy track attributes #119
  • Loading branch information
aviezerl committed May 8, 2024
1 parent cc131ca commit fd29aef
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 4 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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", , "[email protected]", role = "aut"),
person("Aviezer", "Lifshitz", , "[email protected]", role = c("aut", "cre")),
Expand Down Expand Up @@ -54,4 +54,4 @@ Language: en-US
LazyLoad: yes
NeedsCompilation: yes
OS_type: unix
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
2 changes: 0 additions & 2 deletions R/track-attributes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 9 additions & 0 deletions R/track.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
})
}
}


Expand Down
25 changes: 25 additions & 0 deletions man/naryn-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions tests/testthat/test-track.create.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit fd29aef

Please sign in to comment.