Skip to content

Commit

Permalink
correctly prebuild vignettes and name each code chunks (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
PMassicotte committed Dec 12, 2023
1 parent e8a89d3 commit 3709fa6
Show file tree
Hide file tree
Showing 59 changed files with 233 additions and 225 deletions.
1 change: 0 additions & 1 deletion vignettes/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
*.html
*.R
15 changes: 15 additions & 0 deletions vignettes/create_cran_vignettes.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Use this to create the vignette to prevent CRAN checks from failing when
# gitignore API is not available.

# https://ropensci.org/blog/2019/12/08/precompute-vignettes/

library(fs)

infiles <- dir_ls("vignettes", glob = "*.orig")
outfiles <- fs::path_ext_remove(infiles)

purrr::walk2(infiles, outfiles, knitr::knit)

fs::dir_delete("vignettes/figure")
fs::dir_copy("figure", "vignettes/figure", overwrite = TRUE)
fs::dir_delete("figure")
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added vignettes/figure/finding-data.Rmd-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/figure/finding-data.Rmd-5-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added vignettes/figure/language-support.Rmd-3-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
Binary file added vignettes/figure/language-support.Rmd-3-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/figure/language-support.Rmd-3-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/figure/language-support.Rmd-3-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/figure/language-support.Rmd-3-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/figure/language-support.Rmd-3-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added vignettes/figure/language-support.Rmd-3-7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
Binary file added vignettes/figure/rnaturalearth.Rmd-3-1.png
Binary file added vignettes/figure/rnaturalearth.Rmd-3-2.png
Binary file added vignettes/figure/rnaturalearth.Rmd-3-3.png
Binary file added vignettes/figure/rnaturalearth.Rmd-3-4.png
Binary file added vignettes/figure/rnaturalearth.Rmd-3-5.png
Binary file added vignettes/figure/rnaturalearth.Rmd-5-1.png
File renamed without changes
File renamed without changes
File renamed without changes
Binary file added vignettes/figure/what-is-a-country.Rmd-3-4.png
File renamed without changes
File renamed without changes
Binary file added vignettes/figure/what-is-a-country.Rmd-3-7.png
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
36 changes: 15 additions & 21 deletions vignettes/finding-data.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ plot(
#> Geodetic CRS: WGS 84
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-1.png)
![](figure/finding-data.Rmd-3-1.png)

### Cultural vector data

Expand Down Expand Up @@ -178,7 +178,7 @@ plot(
#> Geodetic CRS: WGS 84
```

![plot of chunk unnamed-chunk-5](figure/unnamed-chunk-5-1.png)
![](figure/finding-data.Rmd-5-1.png)

## Searching for countries and continents

Expand All @@ -196,18 +196,18 @@ head(df)
#> Bounding box: xmin: -109.4537 ymin: -55.9185 xmax: 140.9776 ymax: 7.35578
#> Geodetic CRS: WGS 84
#> # A tibble: 6 × 169
#> featurecla scalerank LABELRANK SOVEREIGNT SOV_A3 ADM0_DIF
#> <chr> <int> <int> <chr> <chr> <int>
#> 1 Admin-0 sov… 5 2 Indonesia IDN 0
#> 2 Admin-0 sov… 5 3 Malaysia MYS 0
#> 3 Admin-0 sov… 0 2 Chile CHL 0
#> 4 Admin-0 sov… 0 3 Bolivia BOL 0
#> 5 Admin-0 sov… 0 2 Peru PER 0
#> 6 Admin-0 sov… 0 2 Argentina ARG 0
#> featurecla scalerank LABELRANK SOVEREIGNT SOV_A3 ADM0_DIF
#> <chr> <int> <int> <chr> <chr> <int>
#> 1 Admin-0 so… 5 2 Indonesia IDN 0
#> 2 Admin-0 so… 5 3 Malaysia MYS 0
#> 3 Admin-0 so… 0 2 Chile CHL 0
#> 4 Admin-0 so… 0 3 Bolivia BOL 0
#> 5 Admin-0 so… 0 2 Peru PER 0
#> 6 Admin-0 so… 0 2 Argentina ARG 0
#> # ℹ 163 more variables: LEVEL <int>, TYPE <chr>, TLC <chr>,
#> # ADMIN <chr>, ADM0_A3 <chr>, GEOU_DIF <int>,
#> # GEOUNIT <chr>, GU_A3 <chr>, SU_DIF <int>, SUBUNIT <chr>,
#> # SU_A3 <chr>, BRK_DIFF <int>, NAME <chr>,
#> # GEOUNIT <chr>, GU_A3 <chr>, SU_DIF <int>,
#> # SUBUNIT <chr>, SU_A3 <chr>, BRK_DIFF <int>, NAME <chr>,
#> # NAME_LONG <chr>, BRK_A3 <chr>, BRK_NAME <chr>,
#> # BRK_GROUP <chr>, ABBREV <chr>, POSTAL <chr>,
#> # FORMAL_EN <chr>, FORMAL_FR <chr>, NAME_CIAWF <chr>, …
Expand All @@ -224,10 +224,7 @@ lapply(df$ADMIN[1:6], \(x) {
})
```

<div class="figure">
<img src="figure/unnamed-chunk-7-1.png" alt="plot of chunk unnamed-chunk-7" width="50%" /><img src="figure/unnamed-chunk-7-2.png" alt="plot of chunk unnamed-chunk-7" width="50%" /><img src="figure/unnamed-chunk-7-3.png" alt="plot of chunk unnamed-chunk-7" width="50%" /><img src="figure/unnamed-chunk-7-4.png" alt="plot of chunk unnamed-chunk-7" width="50%" /><img src="figure/unnamed-chunk-7-5.png" alt="plot of chunk unnamed-chunk-7" width="50%" /><img src="figure/unnamed-chunk-7-6.png" alt="plot of chunk unnamed-chunk-7" width="50%" />
<p class="caption">plot of chunk unnamed-chunk-7</p>
</div>
<img src="figure/finding-data.Rmd-7-1.png" width="50%" /><img src="figure/finding-data.Rmd-7-2.png" width="50%" /><img src="figure/finding-data.Rmd-7-3.png" width="50%" /><img src="figure/finding-data.Rmd-7-4.png" width="50%" /><img src="figure/finding-data.Rmd-7-5.png" width="50%" /><img src="figure/finding-data.Rmd-7-6.png" width="50%" />

Suppose that we want to search the polygons for the US, how should we spell it?

Expand All @@ -254,7 +251,7 @@ We can now get the data.
plot(ne_countries(country = "United States of America")["geometry"])
```

![plot of chunk unnamed-chunk-10](figure/unnamed-chunk-10-1.png)
![](figure/finding-data.Rmd-10-1.png)
### Continents

Finally, let's create plots for each continent using the `ne_countries` function with the continent parameter.
Expand All @@ -281,7 +278,4 @@ lapply(unique(df$CONTINENT), \(x) {
})
```

<div class="figure">
<img src="figure/unnamed-chunk-12-1.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-2.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-3.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-4.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-5.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-6.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-7.png" alt="plot of chunk unnamed-chunk-12" width="50%" /><img src="figure/unnamed-chunk-12-8.png" alt="plot of chunk unnamed-chunk-12" width="50%" />
<p class="caption">plot of chunk unnamed-chunk-12</p>
</div>
<img src="figure/finding-data.Rmd-12-1.png" width="50%" /><img src="figure/finding-data.Rmd-12-2.png" width="50%" /><img src="figure/finding-data.Rmd-12-3.png" width="50%" /><img src="figure/finding-data.Rmd-12-4.png" width="50%" /><img src="figure/finding-data.Rmd-12-5.png" width="50%" /><img src="figure/finding-data.Rmd-12-6.png" width="50%" /><img src="figure/finding-data.Rmd-12-7.png" width="50%" /><img src="figure/finding-data.Rmd-12-8.png" width="50%" />
24 changes: 12 additions & 12 deletions vignettes/finding-data.Rmd.orig
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
```{r finding-data.Rmd-1, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
Expand All @@ -25,7 +25,7 @@ There are a lot of data that can be downloaded from [Natural Earth](https://www.

### Physical vector data

```{r, eval=TRUE}
```{r finding-data.Rmd-2, eval=TRUE, fig.cap=''}
data(df_layers_physical)

knitr::kable(
Expand All @@ -36,7 +36,7 @@ knitr::kable(

Based on the previous table, we know that we can download the `ocean` vector at small scale (110). Note that scales are defined as one of `110`, `50`, `10` or `small`, `medium`, `large`.

```{r}
```{r finding-data.Rmd-3, fig.cap=''}
plot(
ne_download(type = "ocean", category = "physical", scale = "small")["geometry"],
col = "lightblue"
Expand All @@ -45,7 +45,7 @@ plot(

### Cultural vector data

```{r, eval=TRUE}
```{r finding-data.Rmd-4, eval=TRUE, fig.cap=''}
data(df_layers_cultural)

knitr::kable(
Expand All @@ -54,7 +54,7 @@ knitr::kable(
)
```

```{r}
```{r finding-data.Rmd-5, fig.cap=''}
plot(
ne_download(
type = "airports",
Expand All @@ -71,7 +71,7 @@ plot(
In this article, we explore how we can search for data available to download within `rnaturalearth`. Let's begin by loading country data using the `read_sf()` function from the `sf` package. In the following code snippet, we read the Natural Earth dataset, which contains information about the sovereignty of countries.


```{r}
```{r finding-data.Rmd-6, fig.cap=''}
df <- read_sf("/vsizip/vsicurl/https://www.naturalearthdata.com/http//www.naturalearthdata.com/download/10m/cultural/ne_10m_admin_0_sovereignty.zip")

head(df)
Expand All @@ -81,7 +81,7 @@ head(df)

One way to search for countries is to search within the `ADMIN` vector. Let's start by plotting some of the first countries.

```{r, echo=-1, fig.show="hold", out.width="50%", results='hide'}
```{r finding-data.Rmd-7, echo=-1, fig.show="hold", out.width="50%", results='hide', fig.cap=''}
par(mfrow = c(2, 3))
lapply(df$ADMIN[1:6], \(x) {
plot(ne_countries(country = x)["geometry"], main = x)
Expand All @@ -90,7 +90,7 @@ lapply(df$ADMIN[1:6], \(x) {

Suppose that we want to search the polygons for the US, how should we spell it?

```{r, eval=FALSE}
```{r finding-data.Rmd-8, eval=FALSE, fig.cap=''}
ne_countries(country = "USA")
ne_countries(country = "United States")
ne_countries(country = "United States Of America")
Expand All @@ -99,23 +99,23 @@ ne_countries(country = "United States of America")

One possibility consists to search within the `ADMIN` vector using a regular expression to find all occurrences of the word *states*.

```{r}
```{r finding-data.Rmd-9, fig.cap=''}
df$ADMIN[grepl("states", df$ADMIN, ignore.case = TRUE)]
```
We can now get the data.

```{r}
```{r finding-data.Rmd-10, fig.cap=''}
plot(ne_countries(country = "United States of America")["geometry"])
```
### Continents

Finally, let's create plots for each continent using the `ne_countries` function with the continent parameter.

```{r}
```{r finding-data.Rmd-11, fig.cap=''}
unique(df$CONTINENT)
```

```{r, echo=-1, fig.show="hold", out.width="50%", results='hide'}
```{r finding-data.Rmd-12, echo=-1, fig.show="hold", out.width="50%", results='hide', fig.cap=''}
par(mfrow = c(2, 4))
lapply(unique(df$CONTINENT), \(x) {
plot(
Expand Down
20 changes: 10 additions & 10 deletions vignettes/language-support.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ terra::plot(ne_countries(continent = "africa"))
#> max.plot = 168 to plot all
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-1.png)
![](figure/language-support.Rmd-3-1.png)

```r

Expand All @@ -64,7 +64,7 @@ ggplot(sfaf) +
geom_sf(data = sfafc)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-2.png)
![](figure/language-support.Rmd-3-2.png)

```r

Expand All @@ -77,7 +77,7 @@ ggplot(sfaf) +
geom_text_repel(aes(x = X, y = Y, label = name), size = 3)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-3.png)
![](figure/language-support.Rmd-3-3.png)

```r

Expand All @@ -88,7 +88,7 @@ ggplot(sfaf) +
geom_text_repel(aes(x = X, y = Y, label = name_es), size = 3)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-4.png)
![](figure/language-support.Rmd-3-4.png)

```r

Expand All @@ -102,7 +102,7 @@ ggplot(sfaf) +
)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-5.png)
![](figure/language-support.Rmd-3-5.png)

```r

Expand Down Expand Up @@ -132,7 +132,7 @@ ggplot(sfaf) +
)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-6.png)
![](figure/language-support.Rmd-3-6.png)

```r

Expand Down Expand Up @@ -162,7 +162,7 @@ ggplot(sfaf) +
)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-7.png)
![](figure/language-support.Rmd-3-7.png)

```r

Expand All @@ -174,7 +174,7 @@ tm_shape(sfaf) +
tm_text("name", size = 0.75)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-8.png)
![](figure/language-support.Rmd-3-8.png)

```r

Expand All @@ -184,7 +184,7 @@ tm_shape(sfaf) +
tm_text("name_es", size = 0.75)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-9.png)
![](figure/language-support.Rmd-3-9.png)

```r

Expand All @@ -194,4 +194,4 @@ tm_shape(sfaf) +
tm_text("name_de", size = 0.75)
```

![plot of chunk unnamed-chunk-3](figure/unnamed-chunk-3-10.png)
![](figure/language-support.Rmd-3-10.png)
Loading

0 comments on commit 3709fa6

Please sign in to comment.