R/Helper.R

Defines functions extractYear addDays replaceId

# Copyright 2023 Observational Health Data Sciences and Informatics
#
# This file is part of CohortExplorer
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

replaceId <- function(data, useNewId = TRUE) {
  if (useNewId) {
    data <- data %>%
      dplyr::select(-"personId") %>%
      dplyr::rename("personId" = "newId")
  } else {
    data <- data %>%
      dplyr::select(-"newId")
  }
  return(data)
}

addDays <- function(x, n) {
  # Ensure that x is of class Date
  xAsDate <- as.Date(x)

  # Add n days to xAsDate
  newDate <- xAsDate + as.integer(n)

  return(newDate)
}


extractYear <- function(dateColumn) {
  as.numeric(format(dateColumn, "%Y"))
}

Try the CohortExplorer package in your browser

Any scripts or data that you put into this service are public.

CohortExplorer documentation built on Oct. 23, 2023, 5:07 p.m.