ropensci/allodb

Some datasets have factors. Is this intentional?

Closed this issue · 1 comments

Datasets with factor columns:

library(tidyverse)
library(allodb)

data(package = "allodb")[["results"]][ , "Item"] %>% 
  set_names() %>% 
  map(get) %>% 
  keep(is.data.frame) %>% 
  map(~select(., where(is.factor))) %>% 
  keep(\(x) ncol(x) > 0L) %>% 
  map(as_tibble) %>% 
  map(head, 1)
#> $gymno_genus
#> # A tibble: 1 x 2
#>   Family        Genus  
#>   <fct>         <fct>  
#> 1 Araucariaceae Agathis
#> 
#> $koppenMatrix
#> # A tibble: 1 x 2
#>   zone1 zone2
#>   <fct> <fct>
#> 1 Af    Af   
#> 
#> $scbi_stem1
#> # A tibble: 1 x 3
#>   genus species Family     
#>   <fct> <fct>   <fct>      
#> 1 Acer  negundo Sapindaceae

Here is how I would change factors to strings for each dataset:

library(dplyr, warn.conflicts = FALSE)

data <- tibble(x = factor("a"), y = "b")
data
#> # A tibble: 1 x 2
#>   x     y    
#>   <fct> <chr>
#> 1 a     b

data %>% mutate(across(where(is.factor), as.character))
#> # A tibble: 1 x 2
#>   x     y    
#>   <chr> <chr>
#> 1 a     b

Created on 2021-07-26 by the reprex package (v2.0.0)

Changed, thanks!