Skip to content

Commit

Permalink
"exists" virtual track function without parameters now checks for exi…
Browse files Browse the repository at this point in the history
…stance of any value.

Fixes emr_vtrack.create with func = "exists" on categorical track requires specification of values #120
  • Loading branch information
aviezerl committed May 7, 2024
1 parent e263a8a commit 3c4a014
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 10 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# naryn 2.6.28

* Fix: `emr_track.mv` did not move track attributes.
* "exists" virtual track function without parameters now checks for existance of any value.

# naryn 2.6.27

Expand Down
4 changes: 2 additions & 2 deletions R/vtrack.R
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ emr_vtrack.create_from_name <- function(vtrack_name) {
#' CATEGORICAL DATA SOURCE
#'
#' \tabular{lll}{ FUNC \tab PARAM \tab DESCRIPTION \cr value \tab vals/NULL
#' \tab A source value or -1 if there is more than one. \cr exists \tab vals
#' \tab 1 if any of the 'vals' exist otherwise 0. \cr sample \tab NULL \tab
#' \tab A source value or -1 if there is more than one. \cr exists \tab vals/NULL
#' \tab 1 if any of the 'vals' exist otherwise 0. NULL indicates the existence of any value\cr sample \tab NULL \tab
#' Uniformly sampled source value. \cr sample.time \tab NULL \tab Time of the
#' uniformly sampled source value. \cr frequent \tab vals/NULL \tab The most
#' frequent source value or -1 if there is more than one value. \cr size \tab
Expand Down
4 changes: 2 additions & 2 deletions man/emr_vtrack.create.Rd

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

3 changes: 0 additions & 3 deletions src/NRTrackExpressionVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,6 @@ void NRTrackExpressionVars::add_vtrack_var(const string &vtrack, SEXP rvtrack, b
} else {
var.percentile = numeric_limits<double>::quiet_NaN();

if (ifunc == EMRTrack::EXISTS && isNull(rparams))
verror("Virtual track %s: function %s requires an additional parameter", vtrack.c_str(), func.c_str());

if (is_categorical) {
if (!isNull(rparams)) {
// params are a single NA value
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test-vtrack.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,13 @@ test_that("emr_vtrack works", {
expect_equal(vt_name, "v1")
})

test_that("function exists requires an additional parameter", {
test_that("function exists without additional parameters looks for all of them", {
emr_vtrack.clear()
expect_error(emr_vtrack.create("v1", "track6", func = "exists"))
expect_error(emr_extract("v1"))
emr_vtrack.create("v1", "track6", func = "exists")
emr_vtrack.create("size", "track6", func = "size")
res <- emr_extract(c("v1", "size"), iterator = "track1") %>%
mutate(f = as.numeric(size > 0))
expect_equal(res$f, res$v1)
})

test_that("emr_vtrack works", {
Expand Down

0 comments on commit 3c4a014

Please sign in to comment.