generated from labordynamicsinstitute/presentation-r-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
bonus.Rmd
82 lines (56 loc) · 1.39 KB
/
bonus.Rmd
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
---
title: "Creating reproducible packages when data are confidential: Bonus slides"
author:
- "Lars Vilhuber"
date: "`r Sys.Date()`"
output:
ioslides_presentation:
incremental: false
self-included: true
widescreen: true
---
# Use cross-platform programming practices
## Cross-platform programming practices 1
**Use programming-language specific code as much as possible**
Avoid
```{r, eval=FALSE}
system("unzip C:\data\myfile.zip")
```
or
```{stata, eval=FALSE}
shell unzip "C:\data\myfile.zip"
```
## Cross-platform programming practices 1
Most languages have appropriate code:
R:
```{r, eval=FALSE}
unzip(zipfile, files = NULL, list = FALSE, overwrite = TRUE,
junkpaths = FALSE, exdir = ".", unzip = "internal",
setTimes = FALSE)
```
Stata:
```{stata, eval=FALSE}
unzipfile "zipfile.zip" [, replace]
```
## Cross-platform programming practices 2
Use neutral pathnames (mostly forward slashes)
::: {.columns-2}
:::: {.column}
**R**: Use functions to combine paths (and/or use forward slashes), packages to make code more portable.
<div class="red2">
```
basepath <- rprojroot::find_root(rprojroot::has_file("README.md"))
data <- read.dta(file.path(basepath,"path","data.dta"))
```
</div>
::::
:::: {.column}
**Stata**: *always* use forward slashes, even on Windows
<div class="blue2">
```
global data "/my/computer"
use "$data/path/data.dta"
```
</div>
::::
:::