You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is a coercion issue when a variable is a numeric date in data frame (df) and has a character type in metadata.
The first_class() function assigns a character type to date(time) variables. @elimillera@bms63, do you remember why date variables are considered as characters?
Currently, characterTypes has the following values: "character", "char", "text", "date", "posixct", "posixt", "datetime", "time", "partialdate", "partialtime", "partialdatetime", "incompletedatetime", "durationdatetime", "intervaldatetime". It is used in xport_type() to convert both R data type (type.x) and metadata data type (type.y) to numeric or character.
meta_ordered <- left_join(
data.frame(variable = names(.df), type = unlist(table_cols_types)),
metadata,
by = "variable"
) %>%
mutate(
# `_character` is used here as a mask for character, in case someone doesn't
# want 'character' coerced to character
type.x = if_else(type.x %in% characterTypes, "_character", type.x),
type.x = if_else(type.x %in% numericTypes | (grepl("DT$|DTM$|TM$", variable) & !is.na(format)),
"_numeric",
type.x
),
type.y = if_else(is.na(type.y), type.x, type.y),
type.y = tolower(type.y),
type.y = if_else(type.y %in% characterTypes | (grepl("DTC$", variable) & is.na(format)), "_character", type.y),
type.y = if_else(type.y %in% numericTypes, "_numeric", type.y)
)
I don’t think we should use the same list of character types for R data type and metadata type for date(time) variables. When the variable is a numeric date the R data types is "posixct", "posixt", "date" or "time". When the metadata data type is "date", "datetime", "time", then it is a character variable. Considering this difference, we should not use the same values list to convert R data type and metadata data type to numeric or character.
What are your thoughts about that?
What happened?
In reference to #145 👍
It would be great to have both. --DTC variables coerced to chr when they have an other type and no message when there is no coercion.
Session Information
No response
Reproducible Example
No response
The text was updated successfully, but these errors were encountered: