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

Intro R updates #785

Merged
merged 4 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
16 changes: 8 additions & 8 deletions intro-to-R-tidyverse/00b-debugging_resources.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ gloss over an error message without actually reading it. Often, R may be telling
you exactly what is wrong, but if you don't take the time to understand what the
error message means, you will have trouble fixing the error. Error messages
often refer to R terms (e.g.. "argument", "directory") so if you need a refresher
on what some terms mean, we recommend running through the [`intro-to-R` notebook](https://alexslemonade.github.io/training-modules/intro-to-R-tidyverse/01-intro_to_r.nb.html)
or going through Hadley Wickham's [R for Data Science](https://r4ds.had.co.nz/)
on what some terms mean, we recommend running through the [`01-intro_to_base_R.Rmd` notebook](https://github.com/AlexsLemonade/training-modules/blob/master/intro-to-R-tidyverse/01-intro_to_base_R.Rmd)
or going through Hadley Wickham's [R for Data Science](https://r4ds.hadley.nz/).

Secondly, realize that just because you don't receive an error message, doesn't
mean that your code did what you intended it to. You also will need to carefully
Expand Down Expand Up @@ -88,7 +88,7 @@ documentation will give you a lot of the information you need. However, you will
also likely find that not all documentation is thorough or clear.

As we discussed in
[`intro_to_R` notebook](https://alexslemonade.github.io/training-modules/intro-to-R-tidyverse/01-intro_to_r.nb.html),
[`01-intro_to_base_R.Rmd` notebook](https://github.com/AlexsLemonade/training-modules/blob/master/intro-to-R-tidyverse/01-intro_to_base_R.Rmd),
objects have *structures* and *types*. Having input that doesn't match the
requirements that a function has can be a common source of errors. Pay special
attention to what the documentation says about what kind of input and output
Expand Down Expand Up @@ -154,7 +154,7 @@ you use R. Many of these can be relatively simple to fix if you know what they
mean, so we have explained what are the most likely origins of these errors and
we've also included helpful StackOverflow posts or other articles that go over
the same or similar problems, where applicable. Also remember that when we use
this notation: '<FILL_IN_THE_BLANK>', these are placeholders for whatever
this notation: `<FILL_IN_THE_BLANK>`, these are placeholders for whatever
specific object, filename, function name or what have you, might be reported.

#### _Example Error 1:_ "No such file or directory"
Expand All @@ -169,7 +169,7 @@ to where R is looking for the file that you are referencing, and double check
that the file you are looking at is where you think it is. This
[StackOverflow post](https://stackoverflow.com/questions/16798605/cannot-open-file-reason-no-such-file-or-directory)
shows why using `file.path` function can help avoid this error in some situations.
RStudio also has a [blog post](https://support.rstudio.com/hc/en-us/articles/200711843-Working-Directories-and-Workspaces)
RStudio also has a [blog post](https://support.posit.co/hc/en-us/articles/200711843-Working-Directories-and-Workspaces-in-the-RStudio-IDE)
that touches on this subject.

#### _Example Error 2:_ "could not find function"
Expand Down Expand Up @@ -202,7 +202,7 @@ you can try to re-install the package using `install.packages` function or if
it's from Bioconductor `BiocManager::install` and then try again. If the package
fails to install, there can be a number of reasons it failed, so you will need
to troubleshoot that on your own, following the approaches we laid out in the
first part of this document. This [RStudio blog](https://support.rstudio.com/hc/en-us/articles/200554786-Problem-Installing-Packages)
first part of this document. This [RStudio blog](https://support.posit.co/hc/en-us/articles/200554786-Problem-Installing-Packages-in-the-RStudio-IDE)
covers some reasons installation may have failed. This [StackOverflow post](https://stackoverflow.com/questions/25721884/how-should-i-deal-with-package-xxx-is-not-available-for-r-version-x-y-z-wa)
also discusses how to attack problems with installing packages.

Expand All @@ -217,7 +217,7 @@ looking for what types of objects the function is built to use. After you
determine what type of object the function is looking for, you can attempt to
convert it by using `as.numeric` or the respective `as.<TYPE>` function.
If you are trouble with this error often, we recommend you take another look
through the [`intro_to_R` notebook](https://alexslemonade.github.io/training-modules/intro-to-R-tidyverse/01-intro_to_r.nb.html)
through the [`01-intro_to_base_R.Rmd` notebook](https://github.com/AlexsLemonade/training-modules/blob/master/intro-to-R-tidyverse/01-intro_to_base_R.Rmd)
or if you'd like a more advanced explanation, we recommend
[Hadley Wickham's Advanced R chapter](http://adv-r.had.co.nz/S3.html) on the handling of
object types.
Expand Down Expand Up @@ -245,7 +245,7 @@ capitalization and punctuation so even the smallest typo can break your code.
So for this error, it's particularly important to check the `Arguments` section
of the function's documentation.

## Some other resources about debugging:
## Some other resources about debugging
- [R's introduction to getting help](https://www.r-project.org/help.html)
- [Tips for debugging code](https://blog.hartleybrody.com/debugging-code-beginner/)

Expand Down
6 changes: 3 additions & 3 deletions intro-to-R-tidyverse/00c-good_scientific_coding_practices.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ Just how incorrect punctuation and grammar can distract a reader from the messag
Your code is not as useful if it isn't easily readable, which is why naming conventions, code style, and consistency are important.

We suggest following a style guide like one of these:
- [Hadley Wickham's R Style Guide](http://adv-r.had.co.nz/Style.html)
- [Google's R Style Guide](https://google.github.io/styleguide/Rguide.xml).
- [The Tidyverse Style Guide](https://style.tidyverse.org/)
- [Google's R Style Guide](https://google.github.io/styleguide/Rguide.xml)

## `set.seed()` helps people reproduce your results

Expand Down Expand Up @@ -92,4 +92,4 @@ This way, when others try to reproduce your research, they know what packages yo

- ['Ten simple rules' for reproducible computational research (PLOS)](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1003285)
- ['Ten simple rules' for documenting scientific software (PLOS)](https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006561)
- [Guide to reproducible code](https://github.com/crazyhottommy/getting-started-with-genomics-tools-and-resources/blob/master/guide-to-reproducible-code.pdf)
- [Guide to reproducible code](https://github.com/crazyhottommy/getting-started-with-genomics-tools-and-resources/blob/f01008791135887d973469869ceb074082666210/guide-to-reproducible-code.pdf)
2 changes: 1 addition & 1 deletion intro-to-R-tidyverse/01-intro_to_base_R.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ This notebook will demonstrate how to:
#### *More resources for learning R*

- [Swirl, an interactive tutorial](https://swirlstats.com/)
- [_R for Data Science_ book](https://r4ds.had.co.nz/)
- [_R for Data Science_ book]((https://r4ds.hadley.nz/)
- [Tutorial on R, RStudio and R Markdown](https://ismayc.github.io/rbasics-book/)
- [Handy R cheatsheets](https://www.posit.co/resources/cheatsheets/)
- [R Markdown website](https://rmarkdown.rstudio.com)
Expand Down
2 changes: 1 addition & 1 deletion intro-to-R-tidyverse/02-intro_to_ggplot2.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ We performed three sets of contrasts:
- [ggplot2 website](https://ggplot2.tidyverse.org/)
- [Handy cheatsheet for ggplot2 (pdf)](https://github.com/rstudio/cheatsheets/raw/main/data-visualization.pdf)
- [_Data Visualization, A practical introduction_](https://socviz.co/)
- [Data visualization chapter of _R for Data Science_](https://r4ds.had.co.nz/data-visualisation.html)
- [Data visualization chapter of _R for Data Science_](https://r4ds.hadley.nz/data-visualize)
sjspielman marked this conversation as resolved.
Show resolved Hide resolved
- [ggplot2 online tutorial](http://r-statistics.co/Complete-Ggplot2-Tutorial-Part1-With-R-Code.html)

## Set Up
Expand Down
4 changes: 2 additions & 2 deletions intro-to-R-tidyverse/03-intro_to_tidyverse.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ It is a pre-processed [astrocytoma microarray dataset](https://www.refine.bio/ex

**More tidyverse resources:**

- [R for Data Science](https://r4ds.had.co.nz/)
- [R for Data Science](https://r4ds.hadley.nz/)
- [tidyverse documentation](https://tidyverse.org/)
- [`dplyr` documentation](https://dplyr.tidyverse.org/)
- [`readr` documentation](https://readr.tidyverse.org/)
Expand Down Expand Up @@ -178,7 +178,7 @@ What information is contained in `gene_df`?
One nifty feature that was added to `R` in version 4.1 is the pipe: `|>`.
Pipes are very handy things that allow you to funnel the result of one expression to the next, making your code more streamlined and fluently expressing the flow of data through a series of operations.

_Note:_ If you are using a version of `R` prior to 4.1 (or looking at older code), pipe functionality was available through the `magrittr` package , which used a pipe that looked like this: `%>%`.
_Note:_ If you are using a version of `R` prior to 4.1 (or looking at older code), pipe functionality was available through the `magrittr` package, which used a pipe that looked like this: `%>%`.
That pipe was the inspiration for the native R pipe we are using here.
While there are some minor differences, you can mostly treat them interchangeably as long as you load the `magrittr` package or `dplyr`, which also loads that version of the pipe.

Expand Down
2 changes: 1 addition & 1 deletion scRNA-seq-advanced/02-dataset_integration.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ We want to read in just four of these files, as listed previously.
To read in these files, we could use the `readr::read_rds()` function (or the base R `readRDS()`) four times, once for each of the files.
We could also use a `for` loop, which is the approach that many programming languages would lean toward.
A different and more modular coding approach to reading in these files (and more!) is to leverage the [`purrr`](https://purrr.tidyverse.org/) `tidyverse` package, which provides a convenient set of functions for operating on lists.
You can read more about these functions and their power and utility in R in [Chapter 21 of _R for Data Science_](https://r4ds.had.co.nz/iteration.html#for-loops-vs.-functionals).
You can read more about these functions and their power and utility in R in [the _R for Data Science_ e-book](https://r4ds.hadley.nz/iteration.html).
sjspielman marked this conversation as resolved.
Show resolved Hide resolved

Of particular interest is the [`purrr::map()`](https://purrr.tidyverse.org/reference/map.html) family of functions, which can be used to run a given function on each element of a list (or vector) in one call.
The general syntax for `purrr::map()` and friends is:
Expand Down
2 changes: 1 addition & 1 deletion scRNA-seq/05-clustering_markers_scRNA.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ markers[[1]] |>

You can see that this table includes values for all genes, so we would like to make a shorter list.

Because we tend to like [tidy data](https://r4ds.had.co.nz/tidy-data.html), here we use a `tidyverse` function from the [`purrr` package](https://purrr.tidyverse.org) to apply the same operations as above to every element of the `markers` list.
Because we tend to like [tidy data](https://r4ds.hadley.nz/data-tidy.html), here we use a `tidyverse` function from the [`purrr` package](https://purrr.tidyverse.org) to apply the same operations as above to every element of the `markers` list.
We will introduce `purrr` briefly here, but if you want more information and background, we recommend the [`purrr` cheatsheet (PDF)](https://github.com/rstudio/cheatsheets/raw/main/purrr.pdf) and Jenny Bryan's great [`purrr` tutorial](https://jennybc.github.io/purrr-tutorial/index.html).


Expand Down