generated from r4ds/bookclub-template
-
Notifications
You must be signed in to change notification settings - Fork 18
/
03-package-structure.Rmd
145 lines (107 loc) · 6.36 KB
/
03-package-structure.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
# Package structure and state
**Learning objectives:**
- Describe the 5 (+1) states of a package.
- Recognize the differences between a source package and a bundled package.
- Use `.Rbuildignore` to mark files for use only in the source package.
## Package states {-}
- Source: Raw form, editable
- Bundled: Compressed to a single archive file (`.tar.gz`)
- Binary: ~Compiled, OS Specific
- Installed: Decompressed into a local package library
- In memory: Explicitly loaded for use
- (Repository: Source or bundle, hosted on a server)
## Package state transitions {-}
The rest of this chapter digs into the differences & transitions
[![R Packages 2e, Figure 3.2. A chart showing different ways to go from one package state to another: 1. library() puts an installed package into memory. 2. Functions such as install.packages(), devtools::install_github(), and devtools::install() can install a package starting variously in the source, bundle, or binary forms. 3. devtools::build() can create a bundle or a binary. 4. devtools::load_all() puts a source package into memory.](images/03-package-structure/install-load.png)](https://r-pkgs.org/structure.html#fig-installation)
## Source vs bundle {-}
- Source = the rest of this book
- Bundle = compressed ~subset of source
- `vignettes/article.Rmd` →
- `build/vignette.rds` (all vignettes)
- `inst/doc/article.R`
- `inst/doc/article.Rmd`
- `inst/doc/article.html`
- `vignettes/article.Rmd`
- Files from `.Rbuildignore` are excluded
## .Rbuildignore {-}
- `.Rbuildignore` = files for you to use while developing
- Add files with `usethis::use_build_ignore()`
- Usualy `{usethis}` functions will add things
- Be careful about regex formatting
## Bundle vs binary {-}
Binary = platform-specific
- `R/*.R` to `R/*.rdb`, etc (efficient storage of pkg contents)
- `Meta` dir with pkg metadata as `.rds`
- `man` (help) to `html` (index) + `help`
- `src` to `libs` (compiled code)
- `data` converted to more efficient form
- `inst` to top-level directory
- Extraneous files and folders (`README.md`, `build/` `tests`, `vignettes`) dropped
## Installed packages {-}
Installed = on your system, ready to use
[![R Packages 2e, Figure 3.2. A chart showing different ways to go from one package state to another: 1. library() puts an installed package into memory. 2. Functions such as install.packages(), devtools::install_github(), and devtools::install() can install a package starting variously in the source, bundle, or binary forms. 3. devtools::build() can create a bundle or a binary. 4. devtools::load_all() puts a source package into memory.](images/03-package-structure/install-load.png)](https://r-pkgs.org/structure.html#fig-installation)
## In-memory packages {-}
- `library(usethis)` loads installed `{usethis}` into memory
- (technically also attaches it to search path, more in Section 10.4)
- `devtools::load_all()` (`Ctrl + Shift + L`) loads source pkg into memory
## Libraries, library(), require(), and packages {-}
- A **package** is a collection of R code
- A **library** is a directory of installed packages
- In many languages, "library" means what "package" means in R
- [See book about setting up user library with new R installation](https://r-pkgs.org/structure.html#sec-library) (`dir.create(Sys.getenv("R_LIBS_USER"), recursive = TRUE)`)
- `library("pkg", lib.loc = "mylib")` loads `pkg` from `mylib` into memory
- NEVER use inside a package
- `require("pkg", lib.loc = "mylib")` does same but only *warns* if `pkg` is missing
## Meeting Videos {-}
### Cohort 1 {-}
`r knitr::include_url("https://www.youtube.com/embed/3r-EPc9XqxE")`
### Cohort 2 {-}
`r knitr::include_url("https://www.youtube.com/embed/vfrAbmqjR1c")`
### Cohort 3 {-}
`r knitr::include_url("https://www.youtube.com/embed/qXJOy8f9TCM")`
<details>
<summary> Meeting chat log </summary>
```
00:30:11 Isabella Velásquez: RSPM: https://www.rstudio.com/products/package-manager/
00:30:16 Isabella Velásquez: and it’s called PyPI!
01:04:57 Isabella Velásquez: https://pypi.org/
01:15:53 collinberke: Microsoft’s capture of R Packages: https://mran.microsoft.com/documents/rro/reproducibility
```
</details>
### Cohort 4 {-}
Chapters 3 and 4 were covered together.
`r knitr::include_url("https://www.youtube.com/embed/Trrc57hCtVo")`
<details>
<summary> Meeting chat log </summary>
```
00:10:54 defuneste: bad connection tonight
00:12:27 defuneste: I was there with Oluwafemi
00:12:49 defuneste: my main take is that I should move to quarto
00:13:46 Jamie: Good take defuneste. Three core reasons?
00:14:26 defuneste: new stuff will not be implemented in rmd
00:14:46 defuneste: and rmd will just be maintained
00:16:03 Jamie: sweet!
00:16:06 Schafer, Toryn: https://docs.google.com/spreadsheets/d/1AlgFwMR42NjjoG2lcm0hf_pk5ZACw-n8UCwnrny91bU/edit#gid=0
00:16:46 defuneste: surprise test !
00:24:52 defuneste: https://www.openblas.net/
00:28:49 Schafer, Toryn: require is designed for use inside other functions; it returns FALSE and gives a warning (rather than an error as library() does by default) if the package does not exist.
00:36:30 defuneste: https://gitlab.com/dickoa/prepr/
00:37:04 defuneste: her it say windows user need to add rtools
00:37:23 defuneste: as a linux users I nened to install gmp and mpfr
00:37:29 defuneste: needed
00:47:28 defuneste: https://xkcd.com/1168/
00:59:38 defuneste: sudo su -c "R -e \"install.packages('devtools')\"" this in command line to instll a package from shell as a super user
01:02:01 defuneste: see the lengthy manual : https://cran.r-project.org/doc/manuals/r-release/R-intro.html#Invoking-R-from-the-command-line
01:03:18 Schafer, Toryn: "/Users/torynschafer/Library/R/x86_64/4.2/library"
01:03:48 Schafer, Toryn: Sys.getenv("R_LIBS_USER")
01:04:13 defuneste: "/home/defuneste/R/x86_64-pc-linux-gnu-library/4.2"
01:04:18 Ryan McShane: Mine on Windows:
"C:\\Program Files\\R\\library"
01:09:01 defuneste: ~/ is the same for me /home/defuneste/
01:10:25 Neil Birrell: Sorry - I need to head off as someone else has booked the meeting room. Possibly a good question to add to the sheet as well :)
01:12:39 Oluwafemi Oyedele: Thank you !!!
01:16:16 Howard Baek: Thanks for coming!
01:16:45 Jamie: Thanks everyone. I have to go now. See you next week.
01:18:50 Howard Baek: Sorry I had to leave my desk! See everyone next week.
```
</details>