Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working pull request to address remaining rbasics issues #304

Merged
merged 6 commits into from
Dec 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions episodes/01-r-basics.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,27 @@
The 'Environment' window allows you to keep track of the objects you have
created in R.


::::::::::::::::::::::::::::::::::::::::: callout

## Tip: Use of white space for readability

The white spaces surrounding the assignment operator `<-` in the example
above (`first_value <- 1`) are unnecessary. However, including them does make your code
easier to read. There are several style guides you can follow, and choosing
one is up to you, but consistency is key!

A style guide we recommend is the Tidyverse [style guide](https://style.tidyverse.org/).

As they say:

"Good coding style is like correct punctuation: you can manage without it, butitsuremakesthingseasiertoread."

::::::::::::::::::::::::::::::::::::::::::::::::::




::::::::::::::::::::::::::::::::::::::: challenge

## Exercise: Create some objects in R
Expand Down Expand Up @@ -191,8 +212,9 @@
a colored highlight or RStudio gives you a suggested autocompletion you have
chosen a name that has a reserved meaning.
- **Use the recommended assignment operator**: In R, we use '\<- ' as the
preferred assignment operator. '=' works too, but is most commonly used in
passing arguments to functions (more on functions later). There is a shortcut
preferred assignment operator, which is recommended by the Tidyverse
[style guide](https://style.tidyverse.org/) discussed above. '=' works too, but is most
commonly used in passing arguments to functions (more on functions later). There is a shortcut
for the R assignment operator:
- Windows execution shortcut: <KBD>Alt</KBD>\+<KBD>\-</KBD>
- Mac execution shortcut: <KBD>Option</KBD>\+<KBD>\-</KBD>
Expand All @@ -216,7 +238,7 @@
about how to assign the name to "human\_ chr\_number" when the object name we
want is "human\_chr\_number".

![RStudio script warning](fig/rstudio_script_warning.png)

Check warning on line 241 in episodes/01-r-basics.Rmd

View workflow job for this annotation

GitHub Actions / Build markdown source files if valid

[image missing alt-text]: fig/rstudio_script_warning.png

::::::::::::::::::::::::::::::::::::::::::::::::::

Expand Down Expand Up @@ -730,12 +752,15 @@
# current value of 'snp_genes':
# chr [1:7] "OXTR" "ACTN3" "AR" "OPRM1" "CYP1A1" NA "APOA5"

# test to see if "ACTN3" or "APO5A" is in the snp_genes vector
# test to see if "ACTN3", "APO5A", or "actn3" is in the snp_genes vector
# if you are looking for more than one value, you must pass this as a vector

c("ACTN3","APOA5") %in% snp_genes
c("ACTN3","APOA5", "actn3") %in% snp_genes
```

Notice that the gene "actn3" is FALSE? This is because character vectors are case sensitive, so
keep this in mind when subsetting and selecting values from a character vector.

::::::::::::::::::::::::::::::::::::::::: callout

## Tip: What's the difference between the `%in% and the `==` operators?
Expand Down
Loading