generated from r4ds/bookclub-template
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path07_r-startup.Rmd
152 lines (120 loc) · 3.99 KB
/
07_r-startup.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# R Startup
**Learning objectives:**
- Set environment variables in `.Renviron`.
- Run R code at R startup with `.Rprofile`.
- Run R without startup files.
## .Renviron {-}
My `.Renviron` looks something like this:
```
SLACK_SKIPLOAD=TRUE
R_DEFAULT_INTERNET_TIMEOUT=1000
NOT_CRAN=true
RTOOT_DEFAULT_TOKEN=<TOKEN_REDACTED>;user;fosstodon.org
LINKEDIN_TOKEN=<TOKEN_REDACTED>
OPENAI_API_KEY=<TOKEN_REDACTED>
```
Project-specific versions can be useful for [GitHub Actions & shinyapps.io deployments](https://github.com/r4ds/mentordash/blob/main/.github/workflows/deploy_shinyapps.yml).
## .Rprofile {-}
My `.Rprofile` got crazy enough that I made [`{andthis}`](https://github.com/jonthegeek/andthis) for my customizations:
```{r rprofile, eval = FALSE}
# Set this to FALSE (or comment out) to update packages like usethis.
options(jon_load_stuff = TRUE)
# Set package options. Make sure these don't impact how analyses work!
options(
usethis.full_name = "Jon Harmon",
usethis.description = list(
`Authors@R` = 'person("Jon", "Harmon",
email = "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-4781-4346"))',
License = "MIT + file LICENSE"
),
usethis.destdir = "C:/Users/jonth/Dropbox (Personal)/R"
)
options(tidymodels.dark = TRUE)
options(styler.cache_root = "styler-perm")
# Set options that make coding safer.
options(
warnPartialMatchArgs = TRUE,
warnPartialMatchDollar = TRUE,
warnPartialMatchAttr = TRUE
)
# Set up my dev environment (load packages, etc).
if (interactive() && getOption("jon_load_stuff", FALSE)) {
suppressMessages(require(devtools))
suppressMessages(require(reprex))
suppressMessages(require(andthis))
# Show branch + time in console prompt.
prompt::set_prompt(
function(...) {
paste0(
"[",
prompt::git_branch(),
" ",
format(Sys.time(), "%T"),
"] > "
)
}
)
}
```
## R without Startups {-}
If running R from command line:
- `--vanilla`
- `.Rprofile` `r emoji::emoji("x")`
- `.Renviron` `r emoji::emoji("x")`
- `--no-init-file` (general) or `--no-site-file` (site?)
- `.Rprofile` `r emoji::emoji("x")`
- `.Renviron` `r emoji::emoji("check_mark")`
- `--no-environ`
- `.Rprofile` `r emoji::emoji("check_mark")`
- `.Renviron` `r emoji::emoji("x")`
Can also disable `.Rprofile` in project options in Rstudio.
## Wait what's a "site" `Rprofile`? {-}
Mine is here: `C:\Program Files\R\R-4.2.2\etc\Rprofile.site`
It's set up with defaults and notes (I haven't edited):
```{r Rprofile.site, eval = FALSE}
# Things you might want to change
# options(papersize="a4")
# options(editor="notepad")
# options(pager="internal")
# set the default help type
# options(help_type="text")
options(help_type="html")
# set a site library
# .Library.site <- file.path(chartr("\\", "/", R.home()), "site-library")
# set a CRAN mirror
# local({r <- getOption("repos")
# r["CRAN"] <- "http://my.local.cran"
# options(repos=r)})
# Give a fortune cookie, but only to interactive sessions
# (This would need the fortunes package to be installed.)
# if (interactive())
# fortunes::fortune()
```
## Meeting Videos {-}
### Cohort 1 {-}
`r knitr::include_url("https://www.youtube.com/embed/8vROEoMhZV8")`
<details>
<summary> Meeting chat log </summary>
```
00:13:43 Jon Harmon (jonthegeek): usethis::edit_r_environ()
00:24:09 Jon Harmon (jonthegeek): usethis::edit_r_profile()
00:25:31 Jon Harmon (jonthegeek): use_conflicted()
use_reprex()
use_usethis()
use_devtools()
use_partial_warnings()
00:26:32 Jon Harmon (jonthegeek): >
00:27:03 Jon Harmon (jonthegeek): [main 11:42:50] > edit_r_profile()
• Modify 'C:/Users/jonth/Documents/.Rprofile'
• Restart R for changes to take effect
[main 13:25:05] >
00:32:20 Jon Harmon (jonthegeek): [main 13:25:05] > getOption("repos")
CRAN
"https://cran.rstudio.com/"
attr(,"RStudio")
[1] TRUE
[main 13:30:21] >
```
</details>