Follow Hadley Wickham’s style guide, adapted from Google’s style guide (HW’s link to Google is broken). Some of the differences between Google and HW are:

You can use whatever naming conventions you want but be consistent. (This holds more generally, e.g. for choice of tidyverse pipe %>% or native pipe |>, etc.)

In addition:

Firstly, don’t call your matrix ‘matrix’. Would you call your dog ‘dog’? Anyway, it might clash with the function ‘matrix’. (Barry Rowlingson, R-help (October 2004))


thing <- (thing %>%
          mutate(foo=x^2)
)

rather than

thing <- thing %>%
    mutate(foo=x^2)

Consider moving the operator to the next line:

thing <- (thing
     %>% mutate(foo=x^2)
)

This makes it easier to comment out unwanted lines temporarily. - Similarly, for complicated multi-argument expressions, put the comma on the following line to make commenting/deleting arguments easier (JD)

thing <- (thing 
    %>% mutate(foo=x^2
           , bar=x^3
           , bletch=x^4
    )
)

rather than

thing <- thing %>%
    mutate(foo=x^2,
           bar=x^3,
           bletch=x^4)

References

Bryan, Jenny. 2017. “Project-Oriented Workflow.” Tidyverse. https://www.tidyverse.org/blog/2017/12/workflow-vs-script/.