Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #124

Closed
wants to merge 15 commits into from
Closed

Dev #124

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions CRAN-SUBMISSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Version: 2.6.26
Date: 2024-01-14 19:09:33 UTC
SHA: 2c56e06dccf3c5d22dbbd12e4dc746887ff0c28a
Version: 2.6.30
Date: 2024-09-27 08:34:48 UTC
SHA: f465f7137992d8df2e04d2dfa10365e421076390
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.26
Version: 2.6.30
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.2
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export(.naryn)
export(day)
export(days)
export(emr_annotate)
export(emr_char2time)
export(emr_cor)
export(emr_date2time)
export(emr_db.connect)
Expand Down Expand Up @@ -47,14 +48,17 @@ export(emr_filters.info)
export(emr_ids_coverage)
export(emr_ids_vals_coverage)
export(emr_monthly_iterator)
export(emr_posix2time)
export(emr_quantiles)
export(emr_screen)
export(emr_summary)
export(emr_time)
export(emr_time2char)
export(emr_time2date)
export(emr_time2dayofmonth)
export(emr_time2hour)
export(emr_time2month)
export(emr_time2posix)
export(emr_time2year)
export(emr_track.addto)
export(emr_track.attr.export)
Expand Down
18 changes: 18 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# naryn 2.6.30

* Removed non-API calls to R in the C++ code.

# naryn 2.6.29

* Fixed *noRemap* additional issue by adding `Rf_` prefix in the c++ code.

# naryn 2.6.28

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

# naryn 2.6.27

* Fix: do not truncate expression names in `emr_extract` when `tidy=TRUE`.

# naryn 2.6.26

* Added `emr_time2posix`, `emr_posix2time`, `emr_time2char` and `emr_char2time` functions.
* Fixed compilation warnings on M1 Mac.

# naryn 2.6.25
Expand Down
3 changes: 1 addition & 2 deletions R/naryn-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,5 @@
#' @useDynLib naryn emr_dbinit emr_dbreload emr_dbunload emr_db_subset emr_db_subset_ids emr_db_subset_info emr_covariance emr_ids_dist emr_ids_dist_with_iterator emr_ids_vals_dist emr_check_named_filter emr_check_filter_attr_src emr_check_filter_attr_time_shift emr_check_filter_attr_expiration update_logical_tracks_file emr_create_logical emr_remove_logical emr_is_logical emr_logical_track_info emr_ltrack_dependencies emr_get_tracks_attrs update_tracks_attrs_file emr_set_track_attr emr_track_create emr_track_exists emr_logical_track_exists emr_logical_track_names emr_track_db_names emr_track_ids emr_import emr_logical_track_user_info emr_track_info emr_track_names emr_track_mv emr_track_percentile emr_track_rm emr_track_unique emr_check_vtrack emr_check_vtrack_attr_src emr_check_vtrack_attr_func emr_check_vtrack_attr_time_shift emr_check_vtrack_attr_id_map emr_check_vtrack_attr_filter
#' @useDynLib naryn C_emr_dist C_emr_extract C_emr_quantiles C_emr_screen C_emr_summary C_emr_time2hour C_emr_time2dayofmonth C_emr_time2month C_emr_time2year C_emr_date2time C_emr_annotate
#' @aliases naryn-package naryn
#' @docType package
#' @keywords package
NULL
"_PACKAGE"
87 changes: 87 additions & 0 deletions R/time.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,93 @@ emr_time2date <- function(time) {
)
}

#' Convert EMR time to POSIXct
#'
#' These function converts EMR time to POSIXct format. It takes the EMR time as input and returns the corresponding POSIXct object.
#'
#' @param time The EMR time to be converted.
#' @param show_hour Logical value indicating whether to include the hour in the output. Default is FALSE.
#' @param tz Time zone to be used for the output POSIXct object. Default is "UTC".
#' @param posix A POSIXct object to be converted to EMR time.
#'
#' @return A POSIXct object representing the converted time.
#'
#' @examples
#' # 30 January, 1938, 6:00 - birthday of Islam Karimov
#' t1 <- emr_date2time(30, 1, 1938, 6)
#' # September 2, 2016, 7:00 - death of Islam Karimov
#' t2 <- emr_date2time(2, 9, 2016, 7)
#'
#' emr_time2posix(c(t1, t2))
#' emr_time2posix(c(t1, t2), show_hour = TRUE)
#'
#' emr_posix2time(emr_time2posix(c(t1, t2), show_hour = TRUE))
#'
#' # Note that when show_hour = FALSE, the hour is set to 0
#' # and therefore the results would be different from the original time values
#' emr_posix2time(emr_time2posix(c(t1, t2)))
#'
#' @export
emr_time2posix <- function(time, show_hour = FALSE, tz = "UTC") {
year <- emr_time2year(time)
month <- emr_time2month(time)
day <- emr_time2dayofmonth(time)

if (show_hour) {
hour <- emr_time2hour(time)
return(as.POSIXct(paste(year, month, day, hour, sep = "-"), format = "%Y-%m-%d-%H", tz = tz))
}

return(as.POSIXct(paste(year, month, day, sep = "-"), format = "%Y-%m-%d", tz = tz))
}

#' Convert time to character format
#'
#' This function converts a given time value to a character format in the form of "%Y-%m-%d" or "%Y-%m-%d %H:%M:%S" depending on the value of the `show_hour` parameter.
#'
#' @param time The time value to be converted.
#' @param show_hour Logical value indicating whether to include the hour in the output. Default is FALSE.
#' @param char A character string to be converted to EMR time.
#'
#' @return A character string representing the converted time value.
#'
#' @examples
#' # 30 January, 1938, 6:00 - birthday of Islam Karimov
#' t1 <- emr_date2time(30, 1, 1938, 6)
#' # September 2, 2016, 7:00 - death of Islam Karimov
#' t2 <- emr_date2time(2, 9, 2016, 7)
#'
#' emr_time2char(c(t1, t2))
#' emr_time2char(c(t1, t2), show_hour = TRUE)
#'
#' emr_char2time(emr_time2char(c(t1, t2), show_hour = TRUE))
#'
#' # Note that when show_hour = FALSE, the hour is set to 0
#' # and therefore the results would be different from the original time values
#' emr_char2time(emr_time2char(c(t1, t2)))
#'
#' @export
emr_time2char <- function(time, show_hour = FALSE) {
as.character(emr_time2posix(time, show_hour = show_hour))
}

#' @rdname emr_time2posix
#' @export
emr_posix2time <- function(posix) {
day <- as.numeric(format(posix, "%d"))
month <- as.numeric(format(posix, "%m"))
year <- as.numeric(format(posix, "%Y"))
hour <- as.numeric(format(posix, "%H"))

return(emr_date2time(day, month, year, hour))
}

#' @rdname emr_time2char
#' @export
emr_char2time <- function(char) {
return(emr_posix2time(as.POSIXct(char)))
}

#' Convert time periods to internal time format
#'
#' Convert time periods to internal time format
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
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
2 changes: 1 addition & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

0 errors | 0 warnings | 0 notes

* Fixed compilation warnings on M1 Mac.
* Removed non-API calls to R: 'PRENV', 'PRVALUE', 'R_PromiseExpr'.
4 changes: 3 additions & 1 deletion inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@ MAXTIME
MINID
MINTIME
Makevars
Mendelson
NA's
NaN
PARAM
PKGDIR
POSIXct
Postmyocardial
Pre
Prefetch
Expand Down Expand Up @@ -68,6 +69,7 @@ mylist
naryndb
ndarray
ness
noRemap
numpy
param
params
Expand Down
40 changes: 40 additions & 0 deletions man/emr_time2char.Rd

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

42 changes: 42 additions & 0 deletions man/emr_time2posix.Rd

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

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.

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.

Loading
Loading