hadley / r4ds

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

separate_wider_regex example doesn't match style guide? #1559

Closed mdavis-xyz closed 1 year ago

mdavis-xyz commented 1 year ago

On the Regex page, there's this example:

df |> 
  [separate_wider_regex](https://tidyr.tidyverse.org/reference/separate_wider_delim.html)(
    str,
    patterns = [c](https://rdrr.io/r/base/c.html)(
      "<", 
      name = "[A-Za-z]+", 
      ">-", 
      gender = ".", "_", 
      age = "[0-9]+"
    )
  )

When reading it, I was temporarily confused by the gender argument. I thought it was some kind of array of two characters. But actually "_" is a second argument, not part of gender.

Why is it on the same line as gender, when the other string literals ("<") are on their own line?

Should this be

df |> 
  [separate_wider_regex](https://tidyr.tidyverse.org/reference/separate_wider_delim.html)(
    str,
    patterns = [c](https://rdrr.io/r/base/c.html)(
      "<", 
      name = "[A-Za-z]+", 
      ">-", 
      gender = ".",
      "_", 
      age = "[0-9]+"
    )
  )

Normally I wouldn't be so pedantic about style. But since this is a guide for beginners, perhaps style is important.

I can create a PR for this, if there's no particular reason it is the way it is.

mine-cetinkaya-rundel commented 1 year ago

A PR would be great, thank you!