diff --git a/R/helpers.R b/R/helpers.R index e66b93e..3a2596c 100644 --- a/R/helpers.R +++ b/R/helpers.R @@ -37,7 +37,12 @@ for(i in seq_along(idVars)){ # set the desired type - class(input[[which(names(idVars)[i] == names(input))]]) <- idVars[[i]]$datype + + if(idVars[[i]]$datype == "Date"){ + input[[which(names(idVars)[i] == names(input))]] <- as.Date(input[[which(names(idVars)[i] == names(input))]], tryFormats = c("%Y-%m-%d"), optional = TRUE) + } else { + class(input[[which(names(idVars)[i] == names(input))]]) <- idVars[[i]]$datype + } } diff --git a/R/setIDVar.R b/R/setIDVar.R index 860c501..f610e93 100644 --- a/R/setIDVar.R +++ b/R/setIDVar.R @@ -9,7 +9,9 @@ #' @param name [\code{character(1)}]\cr Name of the new identifying variable. #' @param type [\code{character(1)}]\cr data type of the new identifying #' variable. Possible values are \code{"c/character"}, \code{"i/integer"}, -#' \code{"n/numeric"}, \code{"l/logical"}, \code{"D/date"} or \code{"_/skip"}. +#' \code{"n/numeric"}, \code{"l/logical"}, \code{"D/Date"} or \code{"_/skip"}. +#' For \code{"D/Date"}, the value has to follow the form \code{YYYY-MM-DD}, +#' where dates that don't match that are replaced by NA. #' @param value [\code{character(1)}]\cr In case the variable is an implicit #' variable (i.e., which is not in the origin table), specify it here. #' @param columns [\code{integerish(.)}]\cr The column(s) in which the diff --git a/man/setIDVar.Rd b/man/setIDVar.Rd index ea43d7b..5ea79fd 100644 --- a/man/setIDVar.Rd +++ b/man/setIDVar.Rd @@ -25,7 +25,9 @@ information).} \item{type}{[\code{character(1)}]\cr data type of the new identifying variable. Possible values are \code{"c/character"}, \code{"i/integer"}, -\code{"n/numeric"}, \code{"l/logical"}, \code{"D/date"} or \code{"_/skip"}.} +\code{"n/numeric"}, \code{"l/logical"}, \code{"D/Date"} or \code{"_/skip"}. +For \code{"D/Date"}, the value has to follow the form \code{YYYY-MM-DD}, +where dates that don't match that are replaced by NA.} \item{value}{[\code{character(1)}]\cr In case the variable is an implicit variable (i.e., which is not in the origin table), specify it here.}