Skip to content

Commit d62f839

Browse files
committed
Update Rtips README
1 parent 93e594b commit d62f839

File tree

5 files changed

+377
-288
lines changed

5 files changed

+377
-288
lines changed

README.md

Lines changed: 22 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,26 @@
11
# R tips
2-
3-
![](https://img.shields.io/badge/Language-R-blue) ![](https://img.shields.io/badge/Theory-Statistics-orange)
4-
5-
This repository contains R programming tips covering topics across data cleaning, data visualisation, machine learning, statistical theory and data productionisation.
6-
7-
<p align="center">
8-
<img src="https://github.com/erikaduan/r_tips/blob/master/figures/r_milestones.jpg"
9-
width="600"></center>
10-
</p>
11-
12-
Many kudos to [Dr Chuanxin Liu](https://github.com/codetrainee), my former PhD student and code editor, for teaching me how to code in R in my past life as an immunologist.
13-
14-
15-
# Content summary
16-
17-
| Legend | Category |
18-
|--------|----------|
19-
| 📚 | Data cleaning |
20-
| 🎨 | Data visualisation |
21-
| 🔮 | Machine learning |
22-
| 🔨 | Productionisation |
23-
| 🔢 | Statistical theory |
24-
25-
26-
# Tutorials
2+
273
## 🎨 Data visualisation
28-
294
+ [An introduction to `ggplot2` using volcano plots](https://github.com/erikaduan/r_tips/blob/master/tutorials/dv-volcano_plots_with_ggplot/dv-volcano_plots_with_ggplot.md) (Updated)
305
+ [Using `DiagrammeR` to draw flow charts](https://github.com/erikaduan/r_tips/blob/master/tutorials/dv-using_diagrammer/dv-using_diagrammer.md) (Updated)
316

327
## 📚 Data cleaning
33-
348
+ [Data cleaning using `data.table` or `tidyverse` (or Python `Pandas`)](https://github.com/erikaduan/r_tips/blob/master/tutorials/dc-data_table_vs_dplyr/dc-data_table_vs_dplyr.md) (Updated)
35-
+ [Cleaning strings with regular expressions using `stringr`](https://github.com/erikaduan/r_tips/blob/master/tutorials/dc-cleaning_strings/dc-cleaning_strings.md) (Updated)
9+
+ [Cleaning strings using regular expressions with base R or `stringr`](https://github.com/erikaduan/r_tips/blob/master/tutorials/dc-cleaning_strings/dc-cleaning_strings.md) (Updated)
3610

3711
## 🔨 Productionisation
3812
+ [Creating SQL <> R workflows - Part 1](https://github.com/erikaduan/r_tips/blob/master/tutorials/p-sql_to_r_workflows/p-sql_to_r_workflows_part_1.md) (Updated)
3913
+ [Creating SQL <> R workflows - Part 2](https://github.com/erikaduan/r_tips/blob/master/tutorials/p-sql_to_r_workflows/p-sql_to_r_workflows_part_2.md) (Updated)
4014
+ [Automating R Markdown report generation - Part 1](https://github.com/erikaduan/r_tips/blob/master/tutorials/p-automating_rmd_reports/p-automating_rmd_reports_part_1.md) (Updated)
41-
+ [Automating R Markdown report generation - Part 2](https://github.com/erikaduan/r_tips/blob/master/tutorials/p-automating_rmd_reports/p-automating_rmd_reports_part_2.md) (updated)
42-
43-
## 🔮 Machine learning
44-
+ [Working with dummy variables and factors](https://github.com/erikaduan/r_tips/blob/master/tutorials/2020-04-23_dummy-variables-and-factors/2020-04-23_dummy-variables-and-factors.md)
15+
+ [Automating R Markdown report generation - Part 2](https://github.com/erikaduan/r_tips/blob/master/tutorials/p-automating_rmd_reports/p-automating_rmd_reports_part_2.md) (updated)
4516

46-
## 🔢 Statistical theory
17+
## 🔢 Statistical modelling
4718
+ [Introduction to expectation and variance](https://github.com/erikaduan/r_tips/blob/master/tutorials/st-expectations_and_variance/st-expectation_and_variance.md)
4819
+ [Beyond expectations: centrality measures in statistics](https://github.com/erikaduan/r_tips/blob/master/tutorials/2020-07-26_many-roads-to-the-middle/2020-07-26_many-roads-to-the-middle.md)
49-
+ [Introduction to the normal distribution](https://github.com/erikaduan/r_tips/blob/master/tutorials/st-normal_distribution/st-normal_distribution.md)
50-
+ [Introduction to the Chi-squared and F distribution](https://github.com/erikaduan/r_tips/blob/master/tutorials/st-chi_squared_and_f_distributions/st-chi_squared_and_f_distributions.md)
51-
+ [Introduction to binomial distributions](https://github.com/erikaduan/R_tips/blob/master/tutorials/2020-09-12_binomial_distribution/2020-09-12_binomial-distribution.md)
52-
+ [Introduction to hypergeometric, geometric, negative binomial and multinomial distributions](https://github.com/erikaduan/R_tips/blob/master/tutorials/2020-09-22_hypergeometric-and-other-discrete-distributions/2020-09-22_hypergeometric-and-other-discrete-distributions.md)
20+
21+
22+
## 🔮 Machine learning
23+
+ [Working with dummy variables and factors](https://github.com/erikaduan/r_tips/blob/master/tutorials/2020-04-23_dummy-variables-and-factors/2020-04-23_dummy-variables-and-factors.md)
5324

5425

5526
# Other resources
@@ -61,9 +32,9 @@ The resources below also cover a comprehensive range of practical R tutorials.
6132

6233
# Tutorial style guide
6334

64-
A painful form of technical debt is inconsistent code style. This repository now contains the following file naming and code style rules.
35+
This repository now contains the following file naming and code style rules.
6536

66-
+ Folders are no longer ordered with a numerical prefix and names are no longer case sensitive e.e.g `r_tips\tutorials\...` and `r_tips\figures\...`
37+
+ Folders are no longer ordered with a numerical prefix and names are no longer case sensitive e.g `r_tips\tutorials\...` and `r_tips\figures\...`
6738
+ Tutorial subtopics share the same prefix e.g. `r_tips\tutorials\dv-...` and `r_tips\tutorials\st-...`
6839
+ File names contain `-` to separate file name prefixes and `_` instead of other white space e.g. `r_tips\figures\dv-using_diagrammer-simple_flowchart.svg`
6940
+ Comments are styled according to the [tidyverse style guide](https://style.tidyverse.org/functions.html?q=comments#comments-1):
@@ -73,9 +44,9 @@ A painful form of technical debt is inconsistent code style. This repository now
7344
+ Comments should not be followed by a blank line, unless the comment is a stand-alone paragraph containing in-depth rationale or an alternative solution
7445
+ R code chunks are styled as follows:
7546
+ Each R chunk should be named with a short unique description written in the active voice e.g. `create basic plot` and `modify plot labels`
76-
+ Arguments inside code chunks should not contain white space and boolean argument options should be written in capitals e.g. `{r load libraries, message=FALSE, warning = FALSE}`
47+
+ Arguments inside code chunks should not contain white space and boolean argument options should be written in capitals e.g. `{r load libraries, message=FALSE, warning=FALSE}`
7748
+ To render the github document, results are generally suppressed using `results='hide'` and manually entered in a new line beneath the code.
78-
+ To render the github document, figures are generally outputed using `fig.show='hold'` and figure outputs can then be suppressed at the local chunk level using `fig.show='hide'`
49+
+ To render the github document, figures are generally outputed using `fig.show='markdown'` and figure outputs can then be suppressed at the local chunk level using `fig.show='hide'`
7950
+ Set a margin of 80 characters length in RStudio through `Tools\Global options --> Code --> Display --> Show margin` and use this margin as the cut-off for code and comments length
8051

8152
# Citations
@@ -88,4 +59,13 @@ Citing packages is a good practice when you are publishing research papers. To d
8859
1686, https://doi.org/10.21105/joss.01686
8960
+ H. Wickham. `ggplot2`: Elegant Graphics for Data Analysis. Springer-Verlag New York, 2016.
9061
+ Matt Dowle and Arun Srinivasan (2021). `data.table`: Extension of `data.frame`. R package
91-
version 1.14.2. https://CRAN.R-project.org/package=data.table
62+
version 1.14.2. https://CRAN.R-project.org/package=data.table
63+
64+
# Acknowledgements
65+
66+
Many kudos to [Dr Chuanxin Liu](https://github.com/codetrainee), my former PhD student and code editor, for teaching me how to code in R in my past life as an immunologist.
67+
68+
<p align="center">
69+
<img src="https://github.com/erikaduan/r_tips/blob/master/figures/r_milestones.jpg"
70+
width="600"></center>
71+
</p>
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Load required packages -------------------------------------------------------
2+
if (!require("pacman")) install.packages("pacman")
3+
pacman::p_load(dplyr,
4+
purrr)
5+
6+
# Create a manual list of survey responses -------------------------------------
7+
# Each list contains a vector containing 2 atomic elements (rating and comment)
8+
survey_list <- list(
9+
expert_1 = c(
10+
8,
11+
'<textarea name="comment" form="1"> &lt;Grade A beans.&gt; Easily melts.
12+
Smooth chocolate shell, with a crunchy malty filling, and not so sweet <p> I
13+
enjoyed this. </textarea>'
14+
),
15+
expert_2 = c(
16+
7,
17+
'<textarea name="comment" form="1"> &lt;Grade A beans with subtle caramel
18+
hints.&gt; Melts well. Smooth exterior. Glossy coating. Malt-filled core may
19+
be too sweet for some. </textarea>'
20+
),
21+
expert_3 = c(
22+
8,
23+
'<textarea name="comment" form="1"> &lt;Grade A beans.&gt; <p> Caramel and
24+
vanilla undertones complement the bitter dark chocolate - low sugar content
25+
and smooth chocolate shell. <p> Recommended. </textarea>'
26+
),
27+
expert_4 = c(
28+
10, '<textarea name="comment" form="1"> &lt;Grade A cocoa beans.&gt; Melts
29+
easily. Smooth dark chocolate contrasts nicely against the crunchy malty
30+
filling. </textarea>'
31+
),
32+
expert_5 = c(
33+
7,
34+
'<textarea name="comment" form="1"> &lt;Grade A beans,&gt; likely of Ecuador
35+
origin. Smooth dark chocolate coating. Malt filling ratio could be
36+
decreased. Easy to eat. </textarea>'
37+
),
38+
fan_1 = c(
39+
9,
40+
'<textarea name="comment" form="1"> Delicious and melts in your mouth. The
41+
malt crunch is a nice touch <p> Would recommend. </textarea>'),
42+
fan_2 = c(
43+
10,
44+
'<textarea name="comment" form="1"> Smooth dark chocolate shell likely made
45+
from grade A beans. Has some nice crunch. <p> This is definiely one of my
46+
new favourites! </textarea>'
47+
),
48+
fan_3 = c(
49+
8,
50+
'<textarea name="comment" form="1"> Tastes great. Smooth and tasty
51+
chocolate. <p> Highly recommended. </textarea>'),
52+
fan_4 = c(
53+
10,
54+
'<textarea name="comment" form="1"> This will be one of my new favourites.
55+
Love the malty interior! </textarea>'
56+
),
57+
fan_5 = c(
58+
9,
59+
'<textarea name="comment" form="1"> Ive loved Haighs since I was a kid!
60+
Love the caramels the most! </textarea>'
61+
),
62+
fan_6 = c(
63+
9,
64+
'<textarea name="comment" form="1"> Delicious :)!!! </textarea>')
65+
)
66+
67+
# Convert list into tidy data frame --------------------------------------------
68+
# t() produces a nested data frame where every column contains a matrix array
69+
survey <- survey_list %>%
70+
map_df(~ as_tibble(t(.x), .name_repair = "unique")) %>%
71+
mutate(respondee = names(survey_list)) %>%
72+
rename("rating" = "...1",
73+
"comment_field" = "...2") %>%
74+
select(respondee, everything())
75+
76+
# Clean global environment by removing redundant objects -----------------------
77+
rm(list = setdiff(ls(), "survey"))
78+
79+
# Print output -----------------------------------------------------------------
80+
cat("PASS: loaded survey into global R environment\n")

0 commit comments

Comments
 (0)