openwashdata-dev / washr

An R package to make publishing openwashdata resources easier
https://openwashdata-dev.github.io/washr/
Other
1 stars 0 forks source link

setup_dictionary cannot show factor type #5

Closed mianzg closed 2 months ago

mianzg commented 3 months ago

https://github.com/openwashdata-dev/washr/blob/6c3d61ccfcf69880e86dda40cebf1d32b60c959a/R/setup_dictionary.R#L99C5-L99C54

Instead of using typeof(), consider to change into class()

mianzg commented 3 months ago

@larnsce factor is a special case of integer data type in R, so typeof() will return factor variables as integer too. However,class() will not differentiate detailed numeric type, for instance, it will return "numeric" for both "integer" and "double".

What do you think? Or we can add an if-else statement just for factor type.

larnsce commented 3 months ago

I think it's alright to show class numeric for integer or double. It's more meaningful to people that would look at the README anyways.

mianzg commented 2 months ago

Changed it to use class()

mianzg commented 2 months ago

date types will cause an error in var_type <- c(var_type, sapply(tidydata, class))

what happened: class(date object) returns [1] "POSIXct" "POSIXt", therefore, var_type will be a nested list instead of a vector.

expected: var_type should be the same length as file_name and var_name to make a final data frame to output

solution: coerce var_type to be a character vector