@@ -144,6 +144,27 @@ In the 'Environment' window you will also get a table:
144
144
The 'Environment' window allows you to keep track of the objects you have
145
145
created in R.
146
146
147
+
148
+ ::::::::::::::::::::::::::::::::::::::::: callout
149
+
150
+ ## Tip: Use of white space for readability
151
+
152
+ The white spaces surrounding the assignment operator ` <- ` in the example
153
+ above (` first_value <- 1 ` ) are unnecessary. However, including them does make your code
154
+ easier to read. There are several style guides you can follow, and choosing
155
+ one is up to you, but consistency is key!
156
+
157
+ A style guide we recommend is the Tidyverse [ style guide] ( https://style.tidyverse.org/ ) .
158
+
159
+ As they say:
160
+
161
+ "Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread."
162
+
163
+ ::::::::::::::::::::::::::::::::::::::::::::::::::
164
+
165
+
166
+
167
+
147
168
::::::::::::::::::::::::::::::::::::::: challenge
148
169
149
170
## Exercise: Create some objects in R
@@ -193,8 +214,9 @@ Here are some important details about naming objects in R.
193
214
a colored highlight or RStudio gives you a suggested autocompletion you have
194
215
chosen a name that has a reserved meaning.
195
216
- ** Use the recommended assignment operator** : In R, we use '\< - ' as the
196
- preferred assignment operator. '=' works too, but is most commonly used in
197
- passing arguments to functions (more on functions later). There is a shortcut
217
+ preferred assignment operator, which is recommended by the Tidyverse
218
+ [ style guide] ( https://style.tidyverse.org/ ) discussed above. '=' works too, but is most
219
+ commonly used in passing arguments to functions (more on functions later). There is a shortcut
198
220
for the R assignment operator:
199
221
- Windows execution shortcut: <KBD >Alt</KBD >\+ <KBD >\- </KBD >
200
222
- Mac execution shortcut: <KBD >Option</KBD >\+ <KBD >\- </KBD >
@@ -900,16 +922,19 @@ the vector you are searching:
900
922
# current value of 'snp_genes':
901
923
# chr [1:7] "OXTR" "ACTN3" "AR" "OPRM1" "CYP1A1" NA "APOA5"
902
924
903
- # test to see if "ACTN3" or "APO5A " is in the snp_genes vector
925
+ # test to see if "ACTN3", "APO5A", or "actn3 " is in the snp_genes vector
904
926
# if you are looking for more than one value, you must pass this as a vector
905
927
906
- c(" ACTN3" ," APOA5" ) %in% snp_genes
928
+ c(" ACTN3" ," APOA5" , " actn3 " ) %in% snp_genes
907
929
```
908
930
909
931
``` output
910
- [1] TRUE TRUE
932
+ [1] TRUE TRUE FALSE
911
933
```
912
934
935
+ Notice that the gene "actn3" is FALSE? This is because character vectors are case sensitive, so
936
+ keep this in mind when subsetting and selecting values from a character vector.
937
+
913
938
::::::::::::::::::::::::::::::::::::::::: callout
914
939
915
940
## Tip: What's the difference between the ` %in% and the ` ==` operators?
0 commit comments