class: center, middle, inverse, title-slide # Coding style
--- layout: true <div class="my-footer"> <span> <a href="" target="_blank"> </a> </span> </div> --- class: center, middle # Coding style --- ## Style guide >"Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread." > >Hadley Wickham - Tidyverse style guide: http://style.tidyverse.org/ - There's more to it than what we'll cover today. - There are many style guides, google style guide etc. - Best to look at several and find what you like and be consistent with it. --- ## File names and code chunk labels - Do not use spaces in file names and code chunk labels, use `-` or `_` to separate words - Use all lowercase letters ```r # Good ucb-admit.csv # Bad UCB Admit.csv ``` --- ## Object names - Use `_` to separate words in object names - Use informative but short object names - Do not reuse object names within an analysis ```r # Good acs_employed # Bad acs.employed acs2 acs_subset acs_subsetted_for_males ``` --- ## Spacing - Put a space before and after all infix operators (=, +, -, <-, etc.), and when naming arguments in function calls - Always put a space after a comma, and never before (just like in regular English) ```r # Good average <- mean(feet / 12 + inches, na.rm = TRUE) # Bad average<-mean(feet/12+inches,na.rm=TRUE) ``` --- ## ggplot2 - Always end a line with `+` - Always indent the next line ```r # Good ggplot(diamonds, mapping = aes(x = price)) + geom_histogram() # Bad ggplot(diamonds,mapping=aes(x=price))+geom_histogram() ```