-
Notifications
You must be signed in to change notification settings - Fork 1
/
workshop_description.org
executable file
·105 lines (75 loc) · 3.09 KB
/
workshop_description.org
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#+OPTIONS: title:t date:t author:t email:t
#+OPTIONS: toc:t h:6 num:nil |:t todo:nil
#+OPTIONS: *:t -:t ::t <:t \n:t e:t creator:nil
#+OPTIONS: f:t inline:t tasks:t tex:t timestamp:t
#+OPTIONS: html-preamble:t html-postamble:nil
#+PROPERTY: header-args:R :session R:ioc :results output :exports code :tangle yes :comments link :eval no
#+TITLE: Better practices in R,@@html:<br>@@no more copy-paste, no more loops
#+DATE: {{{time(%B %d\, %Y)}}}
#+AUTHOR: Marie-Hélène Burle
#+EMAIL: [email protected]
* Goal
Code more efficiently and develop better R practices: replace repetitions, loops, and lengthy code prone to error by clean functions using the package @@html:<span style="padding: 0em 0.2em 0em 0.2em; color: #000000; background-color: #f9b9b9; border-radius: 3px">@@purrr@@html:</span>@@. Purrr is the tidyverse equivalent to the src_R[:eval no]{apply()} functions, but it has more tools and it is more consistent.
** Example
#+BEGIN_VERBATIM
Create a named vector with the maximum values of all the variables in the mtcars dataset.
#+END_VERBATIM
#+BEGIN_VERSE
Copy-paste method:
#+END_VERSE
Don't do this! It is a hard-coding practice prone to error. Not to mention, very tedious...
#+BEGIN_SRC R
setNames(
c(max(mtcars[1]),
max(mtcars[2]),
max(mtcars[3]),
max(mtcars[4]),
max(mtcars[5]),
max(mtcars[6]),
max(mtcars[7]),
max(mtcars[8]),
max(mtcars[9]),
max(mtcars[10]),
max(mtcars[11])
),
names(mtcars)
)
#+END_SRC
#+BEGIN_VERSE
For loop method:
#+END_VERSE
#+BEGIN_SRC R
max <- vector("double", ncol(mtcars))
for (i in seq_along(mtcars)) {
max[[i]] <- max(mtcars[[i]])
}
setNames(max, names(mtcars))
#+END_SRC
#+BEGIN_VERSE
Purrr method (yeah!):
#+END_VERSE
#+BEGIN_SRC R
map_dbl(mtcars, max)
#+END_SRC
* Target audience
- Intermediate R users comfortable with basic data manipulation and simple functions, or
- Advanced users familiar with functional programming using the src_R[:eval no]{apply()} functions family and interested in discovering the "purrring" way.
* Program
- Quick tips for better reproducibility, portability, and code readability,
- Introduction to functional programming with the tidyverse package purrr.
For more information, please visit the [[https://prosoitos.github.io/International-Ornithological-Congress_r-workshops/][workshop webpage]].
* Software requirements
In order to make the best of this workshop, please bring a laptop with the following installed:
- the *latest* R version (if you usually run R in RStudio, make sure that you also have the latest RStudio),
- the *latest* version of the tidyverse package,
- the *latest* version of the patchwork package.
At the time of this writing, the patchwork package is not yet on CRAN and can be installed by running:
#+BEGIN_SRC R
install.packages("devtools") # if you haven't installed it already
devtools::install_github("thomasp85/patchwork")
#+END_SRC
No data file is needed for this workshop.
Please make sure everything is running before coming. Thank you and see you there!
#+HTML: <br>
------------------------------
/Contact: Marie-Helene Burle, [email protected]/