Explorar o código

Adding option units to setEventTime to allow results to be expressed in any unit available to difftime on top of default years

Andrej hai 10 meses
pai
achega
651487f2e4
Modificáronse 2 ficheiros con 11 adicións e 3 borrados
  1. 7 2
      R/modifyData.R
  2. 4 1
      man/setEventTime.Rd

+ 7 - 2
R/modifyData.R

@@ -124,15 +124,20 @@ getNewValue<-function(x,map){
 #' @param duration name of the output column
 #' @param eventColumn dates of evaluation visits (as.Date)
 #' @param startColumn dates of treatment start or diagnosis (as.Date)
+#' @param units desired units of the result. On top of difftime units also years can be specified
 #'
 #' @return updated data frame
 #'
 #' @export
 
-setEventTime<-function(df,duration='years_to_event',eventColumn='d_os',startColumn='rtstartdate1'){
+setEventTime<-function(df,duration='years_to_event',eventColumn='d_os',startColumn='rtstartdate1',units="years"){
    t0=df[,startColumn]
    t1=df[,eventColumn]
-   df[,duration] <-base::as.numeric(base::difftime(t1, t0, units = "days")) / 365.25
+   if (units=="years"){
+      df[,duration] <-base::as.numeric(base::difftime(t1, t0, units = "days")) / 365.25
+   } else {
+      df[,duration] <-base::as.numeric(base::difftime(t1, t0, units = units)) 
+   }
    df
 }
 

+ 4 - 1
man/setEventTime.Rd

@@ -8,7 +8,8 @@ setEventTime(
   df,
   duration = "years_to_event",
   eventColumn = "d_os",
-  startColumn = "rtstartdate1"
+  startColumn = "rtstartdate1",
+  units = "years"
 )
 }
 \arguments{
@@ -19,6 +20,8 @@ setEventTime(
 \item{eventColumn}{dates of evaluation visits (as.Date)}
 
 \item{startColumn}{dates of treatment start or diagnosis (as.Date)}
+
+\item{units}{desired units of the result. On top of difftime units also years can be specified}
 }
 \value{
 updated data frame