Skip to content

Commit c134ebb

Browse files
authored
Merge pull request #96 from b-cubed-eu/make-pkgdown-lighter
Make pkgdown lighter
2 parents 9b59aad + c3b4efa commit c134ebb

12 files changed

+520
-249
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Add grant ID for Zenodo integration #94
44
* Fix ROR url bug
55
* Add publisher to metadata
6+
* Make pkgdown lighter #93
67

78
# dubicube 0.11.0
89

codemeta.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
},
217217
"SystemRequirements": null
218218
},
219-
"fileSize": "389.183KB",
219+
"fileSize": "1846.484KB",
220220
"citation": [
221221
{
222222
"@type": "SoftwareSourceCode",
1.1 MB
Binary file not shown.
17.8 KB
Binary file not shown.
2.21 KB
Binary file not shown.
279 KB
Binary file not shown.
File renamed without changes.

vignettes/articles/bootstrap-interval-calculation.Rmd

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,14 @@ b3data_package <- read_package(
136136
137137
# Load bird cube data
138138
bird_cube_belgium <- read_resource(b3data_package, "bird_cube_belgium_mgrs10")
139-
head(bird_cube_belgium)
140139
```
141140

142141
We process the cube with **b3gbi**.
143142
First, we select 2000 random rows to make the dataset smaller.
144143
This is to reduce the computation time for this tutorial.
145144
We select the data from 2011 - 2020.
146145

147-
```{r}
146+
```r
148147
set.seed(123)
149148

150149
# Make dataset smaller
@@ -161,6 +160,47 @@ processed_cube <- process_cube(
161160
processed_cube
162161
```
163162

163+
```{r, echo=FALSE, message=FALSE, results='hide'}
164+
if (
165+
system.file("bootstrapping", "processed_cube.rds", package = "dubicube") == ""
166+
) {
167+
# Read data package
168+
b3data_package <- read_package(
169+
"https://zenodo.org/records/15211029/files/datapackage.json"
170+
)
171+
172+
# Load bird cube data
173+
bird_cube_belgium <- read_resource(b3data_package, "bird_cube_belgium_mgrs10")
174+
175+
set.seed(123)
176+
177+
# Make dataset smaller
178+
rows <- sample(nrow(bird_cube_belgium), 2000)
179+
bird_cube_belgium <- bird_cube_belgium[rows, ]
180+
181+
# Process cube
182+
processed_cube <- process_cube(
183+
bird_cube_belgium,
184+
first_year = 2011,
185+
last_year = 2020,
186+
cols_occurrences = "n"
187+
)
188+
189+
saveRDS(
190+
processed_cube,
191+
file.path("..", "..", "inst", "bootstrapping", "processed_cube.rds")
192+
)
193+
} else {
194+
processed_cube <- readRDS(
195+
system.file("bootstrapping", "processed_cube.rds", package = "dubicube")
196+
)
197+
}
198+
```
199+
200+
```{r, echo=FALSE}
201+
processed_cube
202+
```
203+
164204
### Analysis of the data
165205

166206
Let's say we are interested in the mean number of observations per grid cell per year.
@@ -171,8 +211,8 @@ We create a function to calculate this.
171211
```
172212

173213
```{r}
174-
# Function to calculate statistic of interest
175-
# Mean number of observations per grid cell per year
214+
# Function to calculate the statistic of interest
215+
# Mean observations per grid cell per year
176216
mean_obs <- function(data) {
177217
data %>%
178218
dplyr::mutate(x = mean(obs), .by = "cellCode") %>%
@@ -197,7 +237,7 @@ On their own, these values don’t reveal how much uncertainty surrounds them. T
197237

198238
We use the `bootstrap_cube()` function to perform bootstrapping (see also the [bootstrap tutorial](https://b-cubed-eu.github.io/dubicube/articles/bootstrap-method-cubes.html)).
199239

200-
```{r}
240+
```r
201241
bootstrap_results <- bootstrap_cube(
202242
data_cube = processed_cube,
203243
fun = mean_obs,
@@ -207,6 +247,35 @@ bootstrap_results <- bootstrap_cube(
207247
)
208248
```
209249

250+
```{r, echo=FALSE, message=FALSE, results='hide'}
251+
if (
252+
system.file(
253+
"bootstrapping", "bootstrap_results.rds", package = "dubicube"
254+
) == ""
255+
) {
256+
bootstrap_results <- bootstrap_cube(
257+
data_cube = processed_cube,
258+
fun = mean_obs,
259+
grouping_var = "year",
260+
samples = 1000,
261+
seed = 123
262+
)
263+
264+
saveRDS(
265+
bootstrap_results,
266+
file.path("..", "..", "inst", "bootstrapping", "bootstrap_results.rds")
267+
)
268+
} else {
269+
bootstrap_results <- readRDS(
270+
system.file("bootstrapping", "bootstrap_results.rds", package = "dubicube")
271+
)
272+
}
273+
```
274+
275+
```{r, echo=FALSE}
276+
print("Performing whole-cube bootstrap with `boot::boot()`.")
277+
```
278+
210279
### Interval calculation
211280

212281
Now we can use the `calculate_bootstrap_ci()` function to calculate confidence limits. It relies on the following arguments:

vignettes/articles/bootstrap-method-cubes.Rmd

Lines changed: 81 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,23 +101,22 @@ library(dubicube) # Analysis of data quality & indicator uncertainty
101101
We load the bird cube data from the **b3data** data package using **frictionless** (see also [here](https://github.com/b-cubed-eu/b3data-scripts)).
102102
It is an occurrence cube for birds in Belgium between 2000 en 2024 using the MGRS grid at 10 km scale.
103103

104-
```{r}
104+
```r
105105
# Read data package
106106
b3data_package <- read_package(
107107
"https://zenodo.org/records/15211029/files/datapackage.json"
108108
)
109109

110110
# Load bird cube data
111111
bird_cube_belgium <- read_resource(b3data_package, "bird_cube_belgium_mgrs10")
112-
head(bird_cube_belgium)
113112
```
114113

115114
We process the cube with **b3gbi**.
116115
First, we select 2000 random rows to make the dataset smaller.
117116
This is to reduce the computation time for this tutorial.
118117
We select the data from 2011 - 2020.
119118

120-
```{r}
119+
```r
121120
set.seed(123)
122121

123122
# Make dataset smaller
@@ -134,24 +133,71 @@ processed_cube <- process_cube(
134133
processed_cube
135134
```
136135

136+
```{r, echo=FALSE, message=FALSE, results='hide'}
137+
if (
138+
system.file("bootstrapping", "processed_cube.rds", package = "dubicube") == ""
139+
) {
140+
# Read data package
141+
b3data_package <- read_package(
142+
"https://zenodo.org/records/15211029/files/datapackage.json"
143+
)
144+
145+
# Load bird cube data
146+
bird_cube_belgium <- read_resource(b3data_package, "bird_cube_belgium_mgrs10")
147+
148+
set.seed(123)
149+
150+
# Make dataset smaller
151+
rows <- sample(nrow(bird_cube_belgium), 2000)
152+
bird_cube_belgium <- bird_cube_belgium[rows, ]
153+
154+
# Process cube
155+
processed_cube <- process_cube(
156+
bird_cube_belgium,
157+
first_year = 2011,
158+
last_year = 2020,
159+
cols_occurrences = "n"
160+
)
161+
162+
saveRDS(
163+
processed_cube,
164+
file.path("..", "..", "inst", "inst", "bootstrapping", "processed_cube.rds")
165+
)
166+
} else {
167+
processed_cube <- readRDS(
168+
system.file("bootstrapping", "processed_cube.rds", package = "dubicube")
169+
)
170+
}
171+
```
172+
173+
```{r, echo=FALSE}
174+
processed_cube
175+
```
176+
137177
### Analysis of the data
138178

139179
Let's say we are interested in the mean number of observations per grid cell per year.
140180
We create a function to calculate this.
141181

182+
```{r, echo=FALSE}
183+
# nolint start: object_usage_linter.
184+
```
185+
142186
```{r}
143187
# Function to calculate the statistic of interest
144188
# Mean observations per grid cell per year
145189
mean_obs <- function(data) {
146-
obs <- x <- NULL
147-
148190
data %>%
149191
dplyr::mutate(x = mean(obs), .by = "cellCode") %>%
150192
dplyr::summarise(diversity_val = mean(x), .by = "year") %>%
151193
as.data.frame()
152194
}
153195
```
154196

197+
```{r, echo=FALSE}
198+
# nolint end: object_usage_linter.
199+
```
200+
155201
We get the following results:
156202

157203
```{r}
@@ -182,7 +228,7 @@ We use the `bootstrap_cube()` function to do this. It relies on the following ar
182228
- **`progress`**:
183229
Logical flag to show a progress bar. Set to `TRUE` to enable progress reporting; default is `FALSE`.
184230

185-
```{r}
231+
```r
186232
bootstrap_results <- bootstrap_cube(
187233
data_cube = processed_cube,
188234
fun = mean_obs,
@@ -192,6 +238,35 @@ bootstrap_results <- bootstrap_cube(
192238
)
193239
```
194240

241+
```{r, echo=FALSE, message=FALSE, results='hide'}
242+
if (
243+
system.file(
244+
"bootstrapping", "bootstrap_results.rds", package = "dubicube"
245+
) == ""
246+
) {
247+
bootstrap_results <- bootstrap_cube(
248+
data_cube = processed_cube,
249+
fun = mean_obs,
250+
grouping_var = "year",
251+
samples = 1000,
252+
seed = 123
253+
)
254+
255+
saveRDS(
256+
bootstrap_results,
257+
file.path("..", "..", "inst", "bootstrapping", "bootstrap_results.rds")
258+
)
259+
} else {
260+
bootstrap_results <- readRDS(
261+
system.file("bootstrapping", "bootstrap_results.rds", package = "dubicube")
262+
)
263+
}
264+
```
265+
266+
```{r, echo=FALSE}
267+
print("Performing whole-cube bootstrap with `boot::boot()`.")
268+
```
269+
195270
This returned a list of `"boot"` objects. We can convert this to a dataframe
196271

197272
```{r}

vignettes/articles/group-level-sensitivity.Rmd

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ It relies on the following arguments:
186186
Logical flag to show a progress bar.
187187
Set to `TRUE` to enable progress reporting; default is `FALSE`.
188188

189-
```{r}
189+
```r
190190
cv_results <- cross_validate_cube(
191191
data_cube = processed_cube,
192192
fun = mean_obs,
@@ -195,6 +195,30 @@ cv_results <- cross_validate_cube(
195195
)
196196
```
197197

198+
```{r, echo=FALSE, message=FALSE, results='hide'}
199+
if (
200+
system.file(
201+
"cross_validation", "cv_results.rds", package = "dubicube"
202+
) == ""
203+
) {
204+
cv_results <- cross_validate_cube(
205+
data_cube = processed_cube,
206+
fun = mean_obs,
207+
grouping_var = "year",
208+
out_var = "taxonKey"
209+
)
210+
211+
saveRDS(
212+
cv_results,
213+
file.path("..", "..", "inst", "cross_validation", "cv_results.rds")
214+
)
215+
} else {
216+
cv_results <- readRDS(
217+
system.file("cross_validation", "cv_results.rds", package = "dubicube")
218+
)
219+
}
220+
```
221+
198222
```{r}
199223
head(cv_results)
200224
```
@@ -269,7 +293,7 @@ As stated in the documentation, it is also possible to cross-validate over a dat
269293
In this case, set the argument `processed_cube = FALSE`.
270294
This is implemented allow for flexible use of simple dataframes, while still encouraging the use of `b3gbi::process_cube()` as default functionality.
271295

272-
``` r
296+
```r
273297
cv_results_df <- cross_validate_cube(
274298
data_cube = processed_cube$data, # data.frame object
275299
fun = mean_obs,

0 commit comments

Comments
 (0)