-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.qmd
1521 lines (1140 loc) · 37.9 KB
/
index.qmd
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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
author: "E. David Aja"
footer: "[Personal R Administration](https://github.com/rstats-wtf/wtf-personal-radmin-slides)"
logo: "img/wtf-logo-square-transparent.png"
format:
revealjs:
theme: [night, slides.scss]
highlight-style: a11y
transition: fade
slide-number: true
chalkboard: true
navigation-mode: linear
controls: false
mermaid-format: svg
execute:
freeze: auto
from: markdown+emoji
title: personal radmin
subtitle: throw your computer into the ocean with confidence
---
## Course material
::: r-fit-text
[posit-conf-2024/wtf](https://github.com/posit-conf-2024/wtf)
:::
## a brief personal history:
::: {.columns .scrollable}
::: {.column .fragment width="33%"}
### Auditor
::: r-fit-text
- personal laptop {{< fa brands windows >}}
- RStudio in Citrix {{< fa brands windows >}}
- airgapped Posit Workbench {{< fa brands linux >}}
- airgapped Shiny Server Pro {{< fa brands linux >}}
- Special Issue Individual Laptop {{< fa brands windows >}} {{< fa brands linux >}}
- Special Issue Individual Desktop {{< fa brands windows >}}
- Special Issue Team Desktop {{< fa brands windows >}}
:::
:::
::: {.column .fragment width="33%"}
### Data Scientist
::: r-fit-text
- personal laptop {{< fa brands windows >}}
- work laptop {{< fa brands windows >}}
- RStudio in Citrix {{< fa brands windows >}}
- RStudio Server {{< fa brands linux >}}
:::
:::
::: {.column .fragment width="33%"}
### Solutions Engineer
::: r-fit-text
- personal laptop {{< fa brands windows >}}
- work laptop {{< fa brands apple >}}
- Posit Workbench Demo Server {{< fa brands linux >}}
- Posit Workbench Internal Server {{< fa brands linux >}}
- misc ephemeral environments
:::
:::
:::
::: notes
this is intended to provide context on my priorities / habits of thought:
- it needs to work across operating systems
- You can't depend on having pro features
- avoid admin where possible
- as portable as practical
- audit context means I need to be able to reproduce exactly
- "run this command" preferable to a confluence page of screenshots
:::
## How do I...
::: incremental
- upgrade the version of R I'm using for this project?
- track which package versions I'm using for this project?
- move this project from one machine to another?
:::
::: notes
We're extending the lessons from Day 1 to think about what it means to work with R projects over time.\
That means that in addition to wanting our individual projects to flow smoothly, we also want to strategize about how to manage different versions of the language, different package versions, and different execution contexts. Working on an old project on a new computer is a lot like trying to put an app into production.
:::
# warmup
## :package: library
::: {.fragment fragment-index="1"}
**R packages**
- the natural unit for distributing R code
:::
::: {.fragment fragment-index="2"}
**base R**
- 14 base + 15 recommended packages
- ships with all binary distributions of R
:::
::: {.fragment fragment-index="3"}
**For example, have you used lattice recently?** 🤷
- it came with your R installation, can use out of the box
- `library(lattice)`
:::
## Where do packages live locally?
<br>
By default, in the default library
`.Library`
<br>
All libraries for the current session
`.libPaths()`
<br>
All installed packages
`installed.packages()`
## explore your package library
```{.r}
usethis::use_course("rstats-wtf/wtf-explore-libraries")
# use_course("rstats-wtf/wtf-explore-libraries", destdir = "my/new/location")
usethis::proj_activate("/path/to/my/new/location")
```
{{< countdown "7:30" >}}
# starting R
## why?
Sometimes we want to change the way our code behaves *without* having to change the code.
::: notes
behaves might mean
- "what computer do I think I'm on"
- "is this dev or prod"?
:::
## R startup sequence {.smaller background-color="#cccccc"}
::: r-stack
![](img/R-startup.svg)
:::
## R startup sequence (our focus) {.smaller background-color="#cccccc"}
::: r-stack
![](img/r-startup-focus.svg)
:::
## :warning: Use a newline
::: columns
::: column
startup files **must** end in a newline. <br/> <br/>
R may silently throw away the last line if you don't do this.
:::
::: column
![](img/insert-newline-end-highlight.png)
:::
:::
## `.Renviron`
environment variables
> a \[...\] named value that can affect the way running processes will behave on a computer
## what goes in `.Renviron`
:white_check_mark: R-specific environment variables\
:white_check_mark: API keys or other secrets\
:x: R code
## Editing `.Renviron`
::: {.r .r-fit-text}
`usethis::edit_r_environ(scope = ?)`
:::
::: columns
::: {.column width="40%"}
### user
`~/.Renviron`
:::
::: {.column width="60%"}
### project
`path/to/your/project/.Renviron`
:::
:::
## example `.Renviron`
``` bash
PATH="${RTOOLS40_HOME}\usr\bin;${PATH}" # windows users
CONNECT_API_KEY=DaYK2hBUriSBYUEGIAiyXsRJHSjTYJN3
R_HISTSIZE=100000
RETICULATE_PYTHON=.venv/bin/python
DB_USER=elephant
DB_PASS=p0stgr3s
```
## read environment variables
::: {.r .r-fit-text}
`Sys.getenv()`
:::
## edit your user `.Renviron` {.smaller}
1. `usethis::edit_r_environ()`
2. add `WTF_USER=<your name>_user`
3. restart your R session\
`CTRL + SHIFT + F10`\
`CMD + SHIFT + 0`
4. Retrieve the value of WTF_USER `Sys.getenv("WTF_USER")`
{{< countdown "2:00" >}}
## edit your project `.Renviron` {.smaller}
1. `usethis::edit_r_environ("project")`
2. add `WTF_PROJECT=<your name>_project`
3. restart your R session\
`CTRL + SHIFT + F10`\
`CMD + SHIFT + 0`
4. Retrieve the value of WTF_PROJECT `Sys.getenv("WTF_PROJECT")`
{{< countdown "2:00" >}}
::: question
what's the value of `WTF_USER` after you set `WTF_PROJECT`?
:::
## `.Renviron` recap
project `.Renviron` "short-circuits"
if it exists, your user `.Renviron` will not be evaluated
## `.Rprofile`
R code that runs at the start of each session
## ?interactive()
::: columns
::: column
### `TRUE`
:technologist: <br/>
- sending individual lines of code to the console
<br/> <br/>
::: fragment
:point_up: most `.Rprofile` customization
:::
:::
::: column
### `FALSE`
:robot: <br/>
- knitting an RMarkdown document
- `R -e script.R`
:::
:::
## what to put in `.Rprofile`
- set a default CRAN mirror
- customize [R prompt](https://github.com/gaborcsardi/prompt/)
## what *not* to put in `.Rprofile`
If it matters for code you share, it **should not** be in `.Rprofile`
## why shouldn't these go in `.Rprofile`?
::: incremental
- `options(stringsAsFactors = FALSE)`
- `library(tidyverse)`
- `f <- dplyr::filter`
- `theme_set(theme_bw())`
:::
## discuss with your neighbor
::: question
Why *might* these be safe to put in `.Rprofile`?
:::
<br>
``` r
library(usethis)
library(devtools)
```
{{< countdown "2:00" >}}
## dotfiles
::: r-fit-text
https://github.com/search?q=.Rprofile
:::
## activity
::: panel-tabset
### edit your user `.Rprofile` {.smaller}
1. `usethis::edit_r_profile()`
2. add `print("from my user Rprofile")`
3. restart your R session\
`CTRL + SHIFT + F10`\
`CMD + SHIFT + 0`
4. what value is printed when you restart?
### edit your project `.Rprofile` {.smaller}
1. `usethis::edit_r_profile("project")`
2. add `print("from my project Rprofile")`
3. restart your R session\
`CTRL + SHIFT + F10`\
`CMD + SHIFT + 0`
4. what value is printed when you restart?
:::
{{< countdown "5:00" >}}
## `.Rprofile` recap
project `.Rprofile` "short-circuits"\
if it exists, your user `.Rprofile` will not be evaluated
## wrapping up
::: columns
::: column
### `.Renviron`
- secrets
- environment information
:::
::: column
### `.Rprofile`
- development dependencies
:::
:::
::: notes
Environment variables are inherited by child processes, so setting them early in the startup process is valuable Hosting providers trying to deal with secrets will often let you supply environment variables
:::
# installing R packages
## why
::: r-stack
![](img/slacking-tidyverse.png)
:::
::: notes
having a reason to slack off is fun but being able to get your work done quickly is more fun
:::
## states of R packages
```{mermaid}
%%{init: {"theme": "dark" } }%%
graph TD
Source -- "devtools::build()" --> Bundled
Bundled -- "devtools::build(binary = TRUE)"--> Binary
Binary --"install.packages()"--> Installed
Installed --"library()"--> Loaded
```
::: aside
[R Packages -- Structure](https://r-pkgs.org/Structure.html)
:::
## states of R packages
```{mermaid}
%%{init: {"theme": "dark" } }%%
flowchart TD
subgraph dev
direction LR
Source -- "devtools::build()" --> Bundled
Bundled -- "devtools::build(binary = TRUE)"--> Binary
end
subgraph use
direction LR
Binary --"install.packages()"--> Installed
Installed --"library()"--> Loaded
end
```
::: aside
[R Packages -- Structure](https://r-pkgs.org/Structure.html)
:::
::: notes
- show how to set options for different environment managers
- Install package from github
- Develop your own packages
:::
## Binary
- compiled ahead of time
- easiest / fastest to install
::: notes
you may particularly care about installation speed if you're being billed by the minute for compute time, or if you need computations to finish before a timeout
:::
## where to get binaries
| | CRAN | Posit Public Package Manager (p3m) |
|-----------------------------------|:------------------:|:----------------------------------:|
| {{< fa brands windows >}} windows | :white_check_mark: | :white_check_mark: |
| {{< fa brands apple >}} mac OS | :white_check_mark: | :white_check_mark: |
| {{< fa brands linux >}} linux | :x: | :white_check_mark: |
## are binaries available?
## CRAN
![](img/connectapi-cran-binary-highlight.png)
## may not be the latest
![](img/parallelly-versions-highlight.png)
## may not be the latest
![](img/compile-from-sources-question.png)
## may not be the latest
``` {.r code-line-numbers="6-8"}
> install.packages("parallelly", repos = "https://cran.r-project.org")
Installing package into ‘C:/Users/WDAGUtilityAccount/Documents/R/win-library/4.0’
(as ‘lib’ is unspecified)
There is a binary version available but the source version is later:
binary source needs_compilation
parallelly 1.31.0 1.32.1 FALSE
installing the source package ‘parallelly’
trying URL 'https://cran.r-project.org/src/contrib/parallelly_1.32.1.tar.gz'
Content type 'application/x-gzip' length 124853 bytes (121 KB)
downloaded 121 KB
* installing *source* package 'parallelly' ...
** package 'parallelly' successfully unpacked and MD5 sums checked
** using staged installation
** R
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
converting help for package 'parallelly'
finding HTML links ... done
as.cluster html
autoStopCluster html
availableConnections html
availableCores html
availableWorkers html
canPortBeUsed html
cpuLoad html
find_rshcmd html
freeCores html
freePort html
getOption2 html
isConnectionValid html
isForkedChild html
isForkedNode html
isLocalhostNode html
isNodeAlive html
makeClusterMPI html
makeClusterPSOCK html
parallelly.options html
pid_exists html
supportsMulticore html
*** copying figures
** building package indices
** testing if installed package can be loaded from temporary location
*** arch - i386
*** arch - x64
** testing if installed package can be loaded from final location
*** arch - i386
*** arch - x64
** testing if installed package keeps a record of temporary installation path
* DONE (parallelly)
```
## [Posit Public Package Manager](https://p3m.dev)
![](img/ppm-binaries.png)
## PPM
![](img/rspm-binaries-zoom-highlight.png)
## how do I know I got a binary?
::: panel-tabset
### CRAN {{< fa brands windows >}}
``` {.r code-line-numbers="5,10"}
> install.packages("parallelly", repos = "https://cran.r-project.org")
Installing package into ‘C:/Users/edavi/Documents/R/win-library/4.1’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/bin/windows/contrib/4.1/parallelly_1.32.1.zip'
Content type 'application/zip' length 306137 bytes (298 KB)
downloaded 298 KB
package ‘parallelly’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\edavi\AppData\Local\Temp\Rtmpa2s3e8\downloaded_packages
```
### CRAN {{< fa brands apple >}}
``` {.r code-line-numbers="4,10"}
> install.packages("renv", repos="https://cran.r-project.org")
Installing package into ‘/Users/edavidaja/Library/R/x86_64/4.1/library’
(as ‘lib’ is unspecified)
trying URL 'https://cran.r-project.org/bin/macosx/contrib/4.1/renv_0.15.5.tgz'
Content type 'application/x-gzip' length 1866760 bytes (1.8 MB)
==================================================
downloaded 1.8 MB
The downloaded binary packages are in
/var/folders/b5/fl4ff68d23s148tg1_1gnflc0000gn/T//RtmpMk69B0/downloaded_packages
```
### p3m
``` {.r code-line-numbers="10"}
> install.packages("remotes")
Installing package into ‘C:/Users/WDAGUtilityAccount/AppData/Local/R/win-library/4.2’
(as ‘lib’ is unspecified)
trying URL 'https://p3m.dev/cran/latest/bin/windows/contrib/4.2/remotes_2.4.2.zip'
Content type 'binary/octet-stream' length 399930 bytes (390 KB)
downloaded 390 KB
package ‘remotes’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\WDAGUtilityAccount\AppData\Local\Temp\RtmpA1edRi\downloaded_packages
```
### renv
``` {.r code-line-numbers="5"}
> renv::install("fs")
Retrieving 'https://p3m.dev/cran/latest/bin/windows/contrib/4.2/fs_1.5.2.zip' ...
OK [downloaded 380.9 Kb in 0.5 secs]
Installing fs [1.5.2] ...
OK [installed binary]
Moving fs [1.5.2] into the cache ...
OK [moved to cache in 7.4 milliseconds]
```
:::
## pop quiz, hotshot
::: question
Does [Posit Public Package Manager](https://p3m.dev) serve a binary of `dplyr` for R 3.6?
:::
{{< countdown "2:00" >}}
## Source
- compiled in *your* environment
- requires extra tools when package uses C, C++, Fortran, Rust, etc.
::: notes
- most common reason to install from source is when you want the development version of a package from github One additional complication for \*nix users:
- generally on windows can install and load packages that depend on other lower level libraries quite easily. Explain installing `sf`, for example.
:::
## if you don't have tools
::: panel-tabset
### `make`
``` {.r code-line-numbers="11"}
Running `R CMD build`...
* checking for file 'C:\Users\WDAGUtilityAccount\AppData\Local\Temp\RtmpkTUH61\remotes192027624804\tidyverse-dplyr-36ef054/DESCRIPTION' ... OK
* preparing 'dplyr':
* checking DESCRIPTION meta-information ... OK
* cleaning src
* installing the package to process help pages
-----------------------------------
* installing *source* package 'dplyr' ...
** using staged installation
** libs
Warning in system(cmd) : 'make' not found
ERROR: compilation failed for package 'dplyr'
* removing 'C:/Users/WDAGUT~1/AppData/Local/Temp/Rtmp6hYuyV/Rinst1334d1a23d1/dplyr'
-----------------------------------
ERROR: package installation failed
```
### `g++`
``` {.r code-line-numbers="7"}
Warning in untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers
* installing *source* package 'dplyr' ...
** using staged installation
** libs
c:/Rtools/mingw_64/bin/g++ -std=gnu++11 -I"C:/PROGRA~1/R/R-36~1.3/include" -DNDEBUG -O2 -Wall -mtune=core2 -c filter.cpp -o filter.o
sh: line 1: c:/Rtools/mingw_64/bin/g++: No such file or directory
make: *** [C:/PROGRA~1/R/R-36~1.3/etc/x64/Makeconf:215: filter.o] Error 127
ERROR: compilation failed for package 'dplyr'
* removing 'C:/Users/edavi/DOCUME~1/projects/WTF-PR~1/renv/staging/1/dplyr'
Error: install of package 'dplyr' failed
```
:::
## how to get the tools
::: panel-tabset
### windows {{< fa brands windows >}}
[Rtools](https://cran.r-project.org/bin/windows/Rtools/)
### macOS {{< fa brands apple >}}
[XCode](https://apps.apple.com/us/app/xcode/id497799835?mt=12)
:warning: don't run right now
``` {.bash code-line-numbers="false"}
xcode-select --install
```
### linux {{< fa brands linux >}}
install tools via package manager, e.g.
``` bash
apt install make
```
:::
## got tools?
::: {.r .r-fit-text}
`devtools::has_devel()`
:::
> `## Your system is ready to build packages!`
## system dependencies
::: panel-tabset
### xml2
```{.r code-line-numbers="15-18"}
* installing *source* package ‘xml2’ ...
** package ‘xml2’ successfully unpacked and MD5 sums checked
** using staged installation
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libxml-2.0', required by 'virtual:world', not found
Package libxml-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `libxml-2.0.pc'
to the PKG_CONFIG_PATH environment variable
Package 'libxml-2.0', required by 'virtual:world', not found
Using PKG_CFLAGS=
Using PKG_LIBS=-lxml2
------------------------- ANTICONF ERROR ---------------------------
Configuration failed because libxml-2.0 was not found. Try installing:
* deb: libxml2-dev (Debian, Ubuntu, etc)
* rpm: libxml2-devel (Fedora, CentOS, RHEL)
* csw: libxml2_dev (Solaris)
If libxml-2.0 is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a libxml-2.0.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
--------------------------------------------------------------------
ERROR: configuration failed for package ‘xml2’
* removing ‘/usr/local/lib/R/site-library/xml2’
The downloaded source packages are in
‘/tmp/Rtmp9JMc7F/downloaded_packages’
Warning message:
In install.packages("xml2") :
installation of package ‘xml2’ had non-zero exit status
```
### `openssl`
```{.r code-line-numbers="6-10"}
* installing *source* package ‘s2’ ...
** package ‘s2’ successfully unpacked and MD5 sums checked
** using staged installation
Testing compiler using PKG_CFLAGS=
--------------------------- [ANTICONF] --------------------------------
Configuration failed because openssl was not found. Try installing:
* deb: libssl-dev (Debian, Ubuntu, etc)
* rpm: openssl-devel (Fedora, CentOS, RHEL)
* csw: libssl_dev (Solaris)
* brew: [email protected] (Mac OSX)
If openssl is already installed, check that 'pkg-config' is in your
PATH and PKG_CONFIG_PATH contains a openssl.pc file. If pkg-config
is unavailable you can set INCLUDE_DIR and LIB_DIR manually via:
R CMD INSTALL --configure-vars='INCLUDE_DIR=... LIB_DIR=...'
-------------------------- [ERROR MESSAGE] ---------------------------
tools/version.c:1:10: fatal error: openssl/opensslv.h: No such file or directory
1 | #include <openssl/opensslv.h>
| ^~~~~~~~~~~~~~~~~~~~
compilation terminated.
--------------------------------------------------------------------
ERROR: configuration failed for package ‘s2’
* removing ‘/usr/local/lib/R/site-library/s2’
```
### `units`
```{.r code-line-numbers="8-11"}
* installing *source* package ‘units’ ...
** package ‘units’ successfully unpacked and MD5 sums checked
** using staged installation
configure: units: 0.8-5
...
configure: error:
--------------------------------------------------------------------------------
Configuration failed because libudunits2.so was not found. Try installing:
* deb: libudunits2-dev (Debian, Ubuntu, ...)
* rpm: udunits2-devel (Fedora, EPEL, ...)
* brew: udunits (OSX)
If udunits2 is already installed in a non-standard location, use:
--configure-args='--with-udunits2-lib=/usr/local/lib'
if the library was not found, and/or:
--configure-args='--with-udunits2-include=/usr/include/udunits2'
if the header was not found, replacing paths with appropriate values.
You can alternatively set UDUNITS2_INCLUDE and UDUNITS2_LIBS manually.
--------------------------------------------------------------------------------
See `config.log' for more details
ERROR: configuration failed for package ‘units’
* removing ‘/usr/local/lib/R/site-library/units’
```
### `gdal`
```{.r code-line-numbers="6-9"}
* installing *source* package ‘sf’ ...
** package ‘sf’ successfully unpacked and MD5 sums checked
** using staged installation
configure: CC: gcc
configure: CXX: g++ -std=gnu++17
checking for gdal-config... no
no
configure: error: gdal-config not found or not executable.
ERROR: configuration failed for package ‘sf’
* removing ‘/usr/local/lib/R/site-library/sf’
The downloaded source packages are in
‘/tmp/Rtmp8bqjb0/downloaded_packages’
Warning message:
In install.packages("sf") :
installation of package ‘sf’ had non-zero exit status
```
:::
## bonus complication
runtime dependencies
::: panel-tabset
### :white_check_mark:
```{.r}
> library(sf)
Linking to GEOS 3.12.2, GDAL 3.9.1, PROJ 9.4.1; sf_use_s2() is TRUE
```
### :x:
```{.r}
The downloaded source packages are in
‘/tmp/RtmpIvTerY/downloaded_packages’
> library(sf)
Error: package or namespace load failed for ‘sf’ in dyn.load(file, DLLpath = DLLpath, ...):
unable to load shared object '/usr/local/lib/R/site-library/units/libs/units.so':
libudunits2.so.0: cannot open shared object file: No such file or directory
```
:::
## which sysdeps?
![](img/p3m-sysdeps.png)
## activity
::: question
install a package from r-universe
:::
::: small
1. open the `wtf-explore-libraries` project from earlier
2. `install.packages("gitcellar")` \# not on cran!
3. update your project `.Rprofile`:\
`usethis::edit_r_profile(scope = "project")`
``` {.r code-line-numbers="false"}
options(repos = c(
ropensci = "https://ropensci.r-universe.dev",
CRAN = "https://cloud.r-project.org", # macOS
P3M = "https://p3m.dev/cran/latest" # windows
))
```
4. save `.Rprofile` and restart R
5. `install.packages("gitcellar")`
:::
{{< countdown "5:00" >}}
## discussion
- did you install `gitcellar` from binary or source?
- How do you know?
## wrapping up
binaries are usually preferred, but for development versions of packages, you may need to install from source.
# creating reproducible environments
## why?
put some science in ["data science"](https://www.getdbt.com/coalesce-2021/down-with-data-science)
## [reproducibility strategies](https://environments.rstudio.com/reproduce)
```{r}
library(ggplot2)
library(tibble)
library(ggrepel)
mm <- tribble(
~x, ~y, ~label, ~Description, ~status,
0.1, 0.1, 'Validated', 'Admins test and approve \n a subset of CRAN', TRUE,
0.5, 0.5, 'Shared Baseline', 'All or most of CRAN, \n updated with R versions, \n tied to a system library', TRUE,
0.5, 0.75, 'Wild West', 'Open access, \n not reproducible, \n how we learn', FALSE,
0.8,0.8, 'Snapshot', 'Open access, user or system \n records per-project dependencies', TRUE,
0.75, 0.2, 'Blocked', 'Backdoor package access, \n offline systems without a strategy', FALSE,
0.2, 0.8, 'Ticket System', 'Admins involved, \n no testing, \n slow updates, \n high risk of breakage', FALSE
)
bad1 <- tribble(
~x, ~y, ~label, ~Description, ~status,
0, 0.2, NA, NA, NA,
0, 1,NA, NA, NA,
0.8, 1, NA, NA, NA
)
bad2 <- tribble(
~x, ~y, ~label, ~Description, ~status,
0.2, 0, NA, NA, NA,
1, 0,NA, NA, NA,
1, 0.8, NA, NA, NA
)
good <- tribble(
~x, ~y, ~label, ~Description, ~status,
0, -0.2,NA, NA, NA,
1, 0.8, NA, NA, NA,
0.8, 1, NA, NA, NA,
0, 0.2, NA, NA, NA
)
good2 <- tribble(
~x, ~y, ~label, ~Description, ~status,
0, 0,NA, NA, NA,
0, 0.2, NA, NA, NA,
1, 0.8, NA, NA, NA,
0.2, 0, NA, NA, NA
)
p <- ggplot(mm, aes(x, y)) +
geom_abline(slope = 1, intercept = 0.2, alpha = 0.2) +
geom_polygon(aes(x,y, text = Description), fill = "red", data=bad1, alpha = 0.1) +
geom_polygon(aes(x,y, text = Description), fill = "green", data=good, alpha = 0.1) +
geom_polygon(aes(x,y, text = NULL), fill = "green", data=good2, alpha = 0.1) +
geom_polygon(aes(x,y, text = Description), fill = "red", data=bad2, alpha = 0.1) +
geom_abline(slope = 1, intercept = -0.2, alpha = 0.2) +
geom_point(aes(x, y, color = status, text = Description)) +
geom_text(aes(x, y, label = label), nudge_y = 0.025, nudge_x = 0.025) +
scale_x_continuous(limits = c(0,1), breaks = seq(0,1,0.25), labels = c("Admins","", "", "", "Users")) +
scale_y_continuous(limits = c(0,1), breaks = seq(0,1,0.25), labels = c("Locked Down","", "", "", "Open")) +
theme_minimal() +
scale_color_manual(breaks = NULL, values = c("#ff0000","#a3c586")) +
labs(
x = "Who is Responsible for Reproducing the Environment?",
y = "Package Access",
color = NULL,
title = "Reproducing Environments: Strategies and Danger Zones"
)
p
```
## [reproducibility strategies](https://environments.rstudio.com/reproduce) {transition="none"}
```{r}
p + annotate("rect", xmin = .75, xmax = .95, ymin = .75, ymax = .95, alpha = .2)
```
::: notes
we're focused in particular on systems where we have both access and responsibility
:::
## tools
::: columns
::: column
### p3m
::: r-stack
![](img/icon-rspm.png){.r-stretch}
:::
:::
::: column
### renv
::: r-stack
![](img/renv-small.png){.r-stretch}
:::
:::
:::
::: notes
renv has a number of tools that are helpful for adopting a project-based workflow:
- lockfile records what packages you use and where you instaled them from
- `renv::install()` can handle installation from remote sources, local sources, package versions, bioconductor, rspm
- per-project library isolation with global package cache
- makes it easy to install experimental versions of packages and then roll back to a stable release if it doesn't work out
:::
## p3m
::: r-stack
![](img/icon-rspm.png){.r-stretch}
:::
## p3m: latest
![](img/p3m-latest.png)
## p3m: date-based snapshots
![](img/rspm-2021-03-31-highlight.png)