Skip to content

Commit

Permalink
properly handle dates
Browse files Browse the repository at this point in the history
  • Loading branch information
EhrmannS committed Feb 13, 2024
1 parent d84446a commit 2cd9085
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
7 changes: 6 additions & 1 deletion R/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

}

Expand Down
4 changes: 3 additions & 1 deletion R/setIDVar.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion man/setIDVar.Rd

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

0 comments on commit 2cd9085

Please sign in to comment.