hadley / r4ds

R for data science: a book
http://r4ds.hadley.nz
Other
4.59k stars 4.22k forks source link

14.4.3 Diagnosing widening problems #1606

Open BioinfGuru opened 11 months ago

BioinfGuru commented 11 months ago

Hey,

Great book... love it!

I'm just learning this part of the book and there seems to be a strange behaviour of too_few() with delim = "-" when included on a debugged data frame: the full string is added to column x. It caused me a lot of confusion when studying this section. I'm not sure if this is my lack of understanding or not, but it might be appropriate to add a warning to remove the line of code too_few = "debug" after debugging.

df <- tibble(x = c("1-1-1", "1-1-2", "1-3-1", "1-3-2", "1-1-1")) #debugged
df |> 
  separate_wider_delim(
    x,
    delim = "-",    # <- unexpected behaviour
    names = c("x", "y", "z"),
    too_few = "debug"
  )

df <- tibble(x = c("a10.1.2022", "b10.2.2011", "e15.1.2015")) # debugged
df |> 
  separate_wider_delim(                   
    x,
    delim = ".",    # <- expected behaviour
    names = c("code", "edition", "year"),
    too_few = "debug"
  )

Regards, Kenneth