From 4a3904b7eed66210669b0f5ee82299f174290804 Mon Sep 17 00:00:00 2001 From: Edward Palmer Date: Fri, 27 Jul 2018 10:22:49 +0100 Subject: [PATCH] Fix for vector memory allocation error The new anonymised ccRecords were causing R to crash when using create_cctable(). This is because the findMaxTime function was returning the number of hours since 1970 and forcing vector allocation to this amount. This fixes the issue --- .Rbuildignore | 2 ++ .gitignore | 1 + R/ccTable.R | 12 +++++++++--- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/.Rbuildignore b/.Rbuildignore index 284a847..3c0feba 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -3,3 +3,5 @@ Makefile .travis.yml appveyor.yml paper.md +^.*\.Rproj$ +^\.Rproj\.user$ diff --git a/.gitignore b/.gitignore index bebd5cd..71c1977 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ vignettes/*.pdf # OAuth2 token, see https://github.com/hadley/httr/releases/tag/v0.3 *.httr-oauth +.Rproj.user diff --git a/R/ccTable.R b/R/ccTable.R index 8fa20d8..f12dd51 100644 --- a/R/ccTable.R +++ b/R/ccTable.R @@ -452,9 +452,13 @@ getEpisodePeriod <- function (e, unit="hours") { # The failure of POSIX conversion indicates that this episode is either # anonymised or has a missing or incorrect value of discharge or admission # time. - if (is.na(tadm) || is.na(tdisc)) - period_length <- findMaxTime(e) - else { + if (is.na(tdisc)) { + period_length <- ceiling( + as.numeric( + difftime( + as.POSIXct.numeric(findMaxTime(e), origin = "1970-01-01 00:00:00"), tadm, units = unit) + )) + } else { if (any(is.null(tdisc), is.null(tadm))) period_length <- NULL else @@ -466,6 +470,8 @@ getEpisodePeriod <- function (e, unit="hours") { if (period_length == 0) period_length <- period_length + 1 } + + if (is.null(period_length)) warning("This episode does not have any time series data: ",