Lesson 7: Coding Style and tips & tricks
Sunday, January 7, 2024
```{r}
# Strive for
flights |>
group_by(tailnum) |>
summarize(
delay = mean(arr_delay, na.rm = TRUE),
n = n()
)
# Avoid
flights|>
group_by(tailnum) |>
summarize(
delay = mean(arr_delay, na.rm = TRUE),
n = n()
)
# Avoid
flights|>
group_by(tailnum) |>
summarize(
delay = mean(arr_delay, na.rm = TRUE),
n = n()
)
```
tab
: autocompleteCMD + 7
(default:Alt + -
)CMD+ p
(default: ⌘ + Shift + M
or Ctrl + Shift + M
)CMD + [
(default: CMD + Option + I
or Ctrl + Alt + I
)Shift+ CMD + Return
CMD + Return
F1
Option + CMD + Down (UP)
Option + Down (UP)
CMD + Shift + C
CMD + Shift + '
Shift + Option + CMD +m.
to rename all instances of that symbol in the current chunk.Ctrl + Shift + 1
Option + CMD + Click
Switch to the next tab: Ctrl + Tab
(Like you do in browers)
Switch to the previous tab: Ctrl + Shift + Tab
Zoom Source: Ctrl + Shift + 1
This might not be used frequently, but it is very useful when you need to create a string vector.
If you are interested in this tip, you need to install the package hrbraddins
first. However, this package is not available on CRAN, you need to install it from GitHub. If you are interested in this package, please follow the instructions below. It is a little bit complicated, but it is worth it.
Now you can find the addin hrbraddins
in the addin menu, as I have demonstrated in the video.
Thank you!