+ - 0:00:00
Notes for current slide
Notes for next slide

Don't repeat yourself, talk to yourself! Repeated reporting in the R universe

bit.ly/sharstudioconf

@SharlaGelfand

1
2
3
4

The reports took all year!

They weren't reproducible

They were scattered,

hard to keep track of, boring, manual, repetitive

not easily repeatable

5
6
7
8
9


Reproducibility!

Code all in one place!

It'll be worth it!

We can do new things!

10

Next year arrives

11

Next year arrives

12

SPSS, Excel, Word

Not reproducible

Difficult to keep track of

Manual and repetitive

Not easily repeatable

Time consuming

13

SPSS, Excel, Word

Not reproducible

Difficult to keep track of

Manual and repetitive

Not easily repeatable

Time consuming

My R code

Kind of reproducible

Difficult to keep track of

Manual and repetitive

Not easily repeatable

Time consuming

13

Don't repeat yourself

Talk to yourself!

14

Don't repeat yourself

Abstract away repetitive logic and automate repetitive processes


Copy and pasting is error prone

Focus should be on what changes

Copying over and over and redoing work is pointless

15

Talk to yourself

It's easier to document why you're doing something now than to remember why you did it a year ago


Focus on future-self instead of present-self

Easy-to-read code doesn't explain motivations

16

I cleaned up after myself

17

Reorganize files

18

Reorganize files

19

Default ordering

20

Setup file

21

I made functions

22

23

24

Body: what stays the same

Argument: what changes

25

26

Chatty functions

library(usethis)
ui_info("hi!")

27

Chatty functions

analysis_year <- 2019
ui_todo("Querying demographics data for
{analysis_year}...")

28

Chatty functions

29

I made code templates

30

Artisanal data doesn't require artisanal code


Used to focus on cleaning this data really well

Too specific!

No idea why I did something

31

Code templates


Generalizable code

Super specific instructions

Deal with artisanal data instead of remembering what to do

32

Prescriptive templates

33

Prescriptive templates

34

Automating templates

clean_data <- function(analysis_year) {
usethis::use_template(
template = "clean_data.R",
save_as = "01_clean-data.R",
data = list(analysis_year = analysis_year),
package = "demographicsreport"
)
}
35

Automating templates

clean_data <- function(analysis_year) {
usethis::use_template(
template = "clean_data.R",
save_as = "01_clean-data.R",
data = list(analysis_year = analysis_year),
package = "demographicsreport"
)
}
36

Automating templates

clean_data <- function(analysis_year) {
usethis::use_template(
template = "clean_data.R",
save_as = "01_clean-data.R",
data = list(analysis_year = analysis_year),
package = "demographicsreport"
)
}
37

I put it all together in a package

38

Why make a package?


Organize functions

Home for templates

Better documentation

Share code with coworkers

39

40

41

42

43

44

45

Don't repeat yourself

Cleaned up files

Functions

Templates

Packages

Talk to yourself!

Clear names and ordering

Chatty functions

Prescriptive templates

Package documentation

46

Repeated reporting in the R universe

Reproducible ✅

Easy to keep track of ✅

Minimal manual work ✅

Easily repeatable ✅

Frees up time... to spend making R packages 💁

47

If you have a repetitive task, abstract or automate what you can and loudly communicate the rest!

48

If you have a repetitive task, abstract or automate what you can and loudly communicate the rest!

Don't repeat yourself, talk to yourself!

48

If you have a repetitive task, abstract or automate what you can and loudly communicate the rest!

Don't repeat yourself, talk to yourself!

Slides: bit.ly/sharstudioconf

Tweets: @sharlagelfand

Blog post: bit.ly/usethis4reporting

Images: Amonrat Rungreangfangsai

48
2
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow