reconhub / linelist

An R package to import, clean, and store case data
https://www.repidemicsconsortium.org/linelist
Other
25 stars 5 forks source link

Add warning for duplicated cleaned variable names #101

Closed zkamvar closed 4 years ago

zkamvar commented 4 years ago

This will fix #100 by adding a warning and modifying the variable names so that they work.

library("linelist")
iris$sepal.width <- iris$Sepal.Width
head(clean_data(iris))
#> Warning: Some variable names were duplicated after cleaning and had suffixes attached:
#> 
#>   sepal.width -> sepal_width_1
#>   sepal_length sepal_width petal_length petal_width species sepal_width_1
#> 1          5.1         3.5          1.4         0.2  setosa           3.5
#> 2          4.9         3.0          1.4         0.2  setosa           3.0
#> 3          4.7         3.2          1.3         0.2  setosa           3.2
#> 4          4.6         3.1          1.5         0.2  setosa           3.1
#> 5          5.0         3.6          1.4         0.2  setosa           3.6
#> 6          5.4         3.9          1.7         0.4  setosa           3.9

Created on 2019-10-28 by the reprex package (v0.3.0)

This will also respect protected variable names (notice that the first sepal_width is changed):

library("linelist")
iris$sepal_width <- iris$Sepal.Width
head(clean_data(iris, protect = which(names(iris) == "sepal_width")))
#> Warning: Some variable names were duplicated after cleaning and had suffixes attached:
#> 
#>   Sepal.Width -> sepal_width_1
#>   sepal_length sepal_width_1 petal_length petal_width species sepal_width
#> 1          5.1           3.5          1.4         0.2  setosa         3.5
#> 2          4.9           3.0          1.4         0.2  setosa         3.0
#> 3          4.7           3.2          1.3         0.2  setosa         3.2
#> 4          4.6           3.1          1.5         0.2  setosa         3.1
#> 5          5.0           3.6          1.4         0.2  setosa         3.6
#> 6          5.4           3.9          1.7         0.4  setosa         3.9

Created on 2019-10-28 by the reprex package (v0.3.0)

You can install and test this out via:

remotes::install_github("reconub/linelist#101")