-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME.Rmd
397 lines (286 loc) · 16 KB
/
README.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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
---
title: "Package **_bio_**"
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
<!-- # Package **_bio_** -->
```{r README-0, include=FALSE}
options(bio.local_list = TRUE)
options(
repos = "https://cran.rstudio.com/",
pkgType = "both",
install.packages.check.source = "yes",
install.packages.compile.from.source = "always"
)
Sys.setenv(R_REMOTES_NO_ERRORS_FROM_WARNINGS = "true")
```
<!-- badges: start -->
[![GitHub version](https://img.shields.io/badge/GitHub-`r packageVersion("bio")`-brightgreen.svg)](https://github.com/mokymai/bio)
[![R-CMD-check](https://github.com/mokymai/bio/workflows/R-CMD-check/badge.svg)](https://github.com/mokymai/bio/actions)
[![Updated-on](https://img.shields.io/badge/Updated%20on-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](/commits/master)
[![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://www.tidyverse.org/lifecycle/#experimental)
[![R-CMD-check](https://github.com/mokymai/bio/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/mokymai/bio/actions/workflows/R-CMD-check.yaml)
<!-- badges: end -->
<!-- [![GitHub last commit](https://img.shields.io/github/last-commit/mokymai/bio)](https://github.com/mokymai/bio) -->
Convenience functions to facilitate installation and management of required resources for course unit __*Biostatistics*__ (*BS-2023*).
<center>
<br>
<font color="darkred" size=4>
This package is intended to be used with <b>RStudio 2024.04</b> or newer<br>
and <b>R 4.4.0</b> or newer.<br>
</font>
<font color="darkred" size=3>
Functions may not work correctly with the previous versions of RStudio and R.
</font>
<br><br><br>
</center>
Bug reports and your feedback are welcome at https://github.com/mokymai/bio/issues.
In the report, indicate what operating system you are using.
# Install
To install this package from CRAN-like repository, use code (recommended):
```{r README-1, eval=FALSE}
repos <- c("https://mokymai.github.io/download/", getOption("repos"))
install.packages("bio", repos = repos)
```
<details>
<summary>Install form GitHub</summary>
To install this package from GitHub:
```{r README-2, eval=FALSE}
if (!require(remotes)) install.packages("remotes")
remotes::install_github("mokymai/bio", dependencies = TRUE)
```
Note: installation from *GitHub* requires *RTools* on *Windows*.
</details>
# Examples
## Check information about OS and user
Check information about operating system (OS) and R-related user information.
```{r README-6, paged.print=FALSE, eval=FALSE}
bio::check_user_info()
## Operating system Windows 10 x64 (build 19044)
## Platform x86_64-w64-mingw32/x64 (64-bit)
## LOGNAME
## USERNAME User
## USERPROFILE C:/Users/User
## HOME C:/Users/User
## R_USER C:/Users/User
## R_HOME C:/PROGRA~1/R/R-4.2.2
## R_LIBS_USER C:/Users/User/AppData/Local/R/win-library/4.2
```
## Check information about programs
Check versions of presence of installed R-related and other programs.
Options:
- `"main"`{.r} (default) -- checks for "R", "RStudio", "Quarto", and "Rtools" ("Windows" only) or "R Build Tools" (non-"Windows" only).
- `"all"`{.r} -- additionally checks for presence of "XQuartz" ("Mac" only), "Git" (all systems), and (sometimes) "Meld".
<!-- This check may not work properly on "Mac" and "Linux". -->
```{r README-7a, eval=FALSE}
bio::check_installed_programs()
## ✔ Program R (4.3.1) is installed (recommended >= 4.3.1).
## ✖ Program RStudio is not installed or is not running.
## ✔ Tool Quarto (1.4.268) is installed (recommended >= 1.3.336).
## ✔ Tool Rtools is installed.
```
```{r README-7b, eval=FALSE}
bio::check_installed_programs("all")
## ✔ Program R (4.3.1) is installed (recommended >= 4.2.2, available 4.3.1).
## ✔ Program RStudio (2023.6.1.524) is installed (recommended >= 2023.3.0, available 2023.6.1.524).
## ✔ Tool Quarto (1.4.268) is installed (recommended >= 1.3.336).
## ✔ Tool Rtools is installed.
## ✔ Program Git is installed.
## ✔ Program Meld is installed.
```
## Check installation status of "R" packages
It is recommended to check installation status and version of required packages by name:
```{r README-8-by-name, eval=FALSE, paged.print=FALSE}
bio::check_packages_by_name(c("bio", "remotes", "tidyverse"))
## ✔ Minimal required versions of all 3 packages are already installed.
```
There is a less recommended way (due to lower transparency) to check installation status of packages by topic.
By default, only missing packages or packages with lower versions than recommended are displayed.
Currently available lists can be returned by function `bio::get_pkg_lists_local()`{.r}.
<details>
<summary>Details</summary>
```{r echo=FALSE, results='asis'}
res <- paste0(
"\n",
paste0("- `'", bio:::get_pkg_lists_local(), "'`", collapse = "\n"),
"\n\n"
)
cat(res)
```
</details>
```{r README-8a, eval=FALSE, paged.print=FALSE}
bio::check_packages_by_topic("mini")
## ℹ Reading list 'mini'
## ✔ Minimal required versions of all 19 packages (from list 'mini') are already installed.
```
```{r README-8b, eval=FALSE, paged.print=FALSE}
bio::check_packages_by_topic("mini", include = "newer_on_cran")
## ℹ Reading list 'mini'
## ✔ Minimal required versions of all 19 packages (from list 'mini') are already installed.
## ℹ Note: 1 package has newer version on CRAN.
```
## Update packages
These are the convenience functions to update certain R packages.
The functions restart R before installation if used in RStudio.
Update package **bio**.
```{r README-3a, eval=FALSE}
bio::update_pkg_bio()
```
Check if there are updates for **bio** or its dependency packages.
```{r README-3b, eval=FALSE, paged.print=FALSE}
bio::check_updates_pkg_bio()
## ℹ Analyzing dependencies of package bio
##
## [... truncated ...]
##
## ✔ Minimal required versions of all 26 packages (from list 'bio') are already installed.
```
Update package **snippets**.
```{r README-4, eval=FALSE}
bio::update_pkg_snippets()
```
<!-- Update package **RcmdrPlugin.biostat**. -->
<!-- ```{r README-5a, eval=FALSE} -->
<!-- bio::update_pkg_rcmdr_biostat() -->
<!-- ``` -->
## RStudio settings and user preferences
> Make sure that you understand what you are doing when you try using the functions
that reset RStudio key bindings (shortcut keys), settings or snippets.
> **You may loose _all_ your previous settings.**
### Dictionaries
This function downloads or updates **hunspell** spelling checking dictionaries dictionaries (including Lithuanian) that can be used by RStudio or by tools from **wellspell.addin** package.
```{r eval=FALSE}
bio::rstudio_install_spellcheck_dictionaries()
```
Install improved Lithuanian dictionary.
```{r eval=FALSE}
bio::rstudio_install_spellcheck_dictionary_lt()
## ✔ lt_LT dictionary installed.
## 'C:/Users/ViG/AppData/Roaming/RStudio/dictionaries/languages-system/lt_LT.dic'
```
### Shortcut keys
This function changes shortcut keys in RStudio.
Run function without arguments to see the available options.
```{r README-9a, eval=FALSE, error=TRUE}
bio::rstudio_reset_keybindings()
## Error: The value of argument 'to' is missing.
## Possible options: 'bio-default', 'rstudio-default'.
```
Options:
- `"bio-default"`{.r} -- shortcut keys recommended for course BS-2023.
- `"rstudio-default"`{.r} -- RStudio defaults.
```{r README-9b, eval=FALSE}
bio::rstudio_reset_keybindings(to = "bio-default")
## ✔ Back up copy of shortcut keys was created in 'C:/Users/User/.R/_backup/keybindings/'
## ✔ Shortcut keys were reset to bio-default.
```
: **Table 1.** Some examples of shortcut keys set with option `"bio-default"`{.r}.
| Shortcut | Action |
|--------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------|
| <kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>S</kbd> | Insert inline LaTeX equation (*R Markdown*). |
| <kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>A</kbd> | Use "Tidyverse" style on selected lines of R code. Package **styler** must be installed (*R code*). |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>D</kbd> | Duplicate selected text. |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>S</kbd> | Check spelling in selected text. Package [**wellspell.addin**][wsa] must be installed. |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>Alt</kbd>+<kbd>P</kbd> | Align parts of selected lines at a custom pattern. |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>]</kbd> | Change heading one level down (*R Markdown*) **[!]**. |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>[</kbd> | Change heading one level up or remove heading (*R Markdown*) **[!]**. |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>;</kbd> | Insert lower opening quotes `„`. |
| <kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>'</kbd> | Insert upper closing quotes `“`. |
| <kbd>Ctrl</kbd>+<kbd>E</kbd> | **Insert/Enclose with R code block** (*R Markdown*) **[!]** . |
| <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>T</kbd> | Insert inline code highlighted as R code (R Markdown). |
| <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>NumPad8</kbd> | Insert operator `%*%` (*R code*). |
| <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>NumPad7</kbd> | Insert operator `%in%` (*R code*). |
| <kbd>Ctrl</kbd>+<kbd>Alt</kbd>+<kbd>D</kbd> | Document R package (that you are building). |
[wsa]: https://github.com/nevrome/wellspell.addin
<!-- : **Table 1.** Some examples of shortcut keys set with option `"bio-default"`{.r}. -->
<!-- `r kbd <- function(...) paste(...)` -->
<!-- Shortcut | Action -->
<!-- --------- | ------------------------------------------------------------------------------------------------------------------------------------------- -->
<!-- `r kbd("Ctrl", "Shift", "Alt", "S")` | Check spelling in selected text. Package [**wellspell.addin**](https://github.com/nevrome/wellspell.addin){target="_blank"} must be installed. -->
<!-- `r kbd("Shift", "Alt", "A")` | Use "Tidyverse" style on selected lines of R code. Package **styler** must be installed (*R code*). -->
<!-- `r kbd("Ctrl", "Alt", "D")` | Document R package (that you are building). -->
<!-- `r kbd("Ctrl", "Shift", "D")` | Duplicate selected text. -->
<!-- `r kbd("Ctrl", "Shift", "Alt", "P")` | Align parts of selected lines at a custom pattern. -->
<!-- `r kbd("Ctrl", "Shift", ";")` | Insert lower opening quotes `„`. -->
<!-- `r kbd("Ctrl", "Shift", "'")` | Insert upper closing quotes `“`. -->
<!-- `r kbd("Ctrl", "E")` | **Insert/Enclose with R code block** (*R Markdown*) **[!]** . -->
<!-- `r kbd("Ctrl", "Alt", "T")` | Insert inline code highlighted as R code (R Markdown). -->
<!-- `r kbd("Shift", "Alt", "S")` | Insert inline LaTeX equation (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad0")` | Remove heading/section name (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad1")` | Replace line into/Insert heading (section name) of level 1 (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad2")` | ... of level 2 (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad3")` | ... of level 3 (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad4")` | ... of level 4 (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad5")` | ... of level 5 (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad6")` | ... of level 6 (*R Markdown*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad7")` | Insert operator `%in%` (*R code*). -->
<!-- `r kbd("Ctrl", "Alt", "NumPad8")` | Insert operator `%*%` (*R code*). -->
More on [Customizing Keyboard Shortcuts](https://support.rstudio.com/hc/en-us/articles/206382178-Customizing-Keyboard-Shortcuts){target="_blank"} in RStudio.
### RStudio settings
This function resets RStudio user preferences and settings.
Run function without arguments to see the available options.
```{r README-10a, eval=FALSE, error=TRUE}
bio::rstudio_reset_user_settings()
#> Error: The value of argument 'to' is missing.
#> Possible choices: 'bio-default', 'bio-dark-blue', 'bio-black', 'rstudio-default'.
```
The options:
- `"bio-default"`{.r} -- recommended `bio` settings (and light theme "Textmate (default)");
- `"bio-dark-blue"`{.r} -- recommended `bio` settings (and dark blue theme "Cobalt");
- `"bio-black"`{.r} -- recommended `bio` settings (and black theme "Chaos");
- `"rstudio-default"`{.r} -- default RStudio settings.
```{r README-10b, eval=FALSE}
bio::rstudio_reset_user_settings(to = "bio-default")
```
To check, how your settings differ from the defaults in a certain list, use:
```{r README-10c, eval=FALSE}
bio::rstudio_compare_user_settings(to = "bio-default")
## ℹ Show differences between current and bio-default setting lists.
## ✔ No differences
```
The settings that are not in the list will not be displayed.
Available options of `to` are "bio-default" and "rstudio-default".
### Snippets
The function replaces current R code and R Markdown snippets with those in package "snippets".
```{r, eval=FALSE}
snippets::install_snippets_from_package("snippets", backup = TRUE)
## ✔ File with markdown snippets was updated:
## 'C:/Users/User/AppData/Roaming/RStudio/snippets/markdown.snippets'
## ✔ File with r snippets was updated:
## 'C:/Users/User/AppData/Roaming/RStudio/snippets/r.snippets'
##
## ℹ You will be able to use the snippets after RStudio is closed and reopened.
```
More information on
[Code Snippets](https://support.rstudio.com/hc/en-us/articles/204463668-Code-Snippets){target="_blank"} in RStudio and on package
[**snippets**](https://gegznav.github.io/snippets/){target="_blank"}.
### Restart R and RStudio
If you want to see the effect of changed settings, you should reload RStudio.
You may use this function, which reloads RStudio without closing it:
```{r, eval=FALSE}
bio::restart_rstudio()
```
However, in some cases it is recommended to close and reopen RStudio.
Next, to restart R session without closing RStudio, use:
```{r, eval=FALSE}
bio::restart_r()
```
Useful to apply before trying to install R packages.
<!-- ## RStudio projects -->
<!-- Open (recently used) RStudio project. -->
<!-- ```{r README-11, eval=FALSE} -->
<!-- bio::open_project() -->
<!-- ## -->
<!-- ## Choose the name of the project (press 0 to cancel): -->
<!-- ## -->
<!-- ## 1: project-1 -->
<!-- ## 2: _learn -->
<!-- ## 3: biostatistics -->
<!-- ## -->
<!-- ## Selection: 0 -->
<!-- ## Cancelled by user. -->
<!-- ``` -->
<!-- Copy the recent projects to your personal project list. -->
<!-- ```{r README-12, eval=FALSE} -->
<!-- bio::update_rstudio_proj_list_user() -->
<!-- ``` -->