|
| 1 | +--- |
| 2 | +title: "Tutorial" |
| 3 | +output: rmarkdown::html_vignette |
| 4 | +vignette: > |
| 5 | + %\VignetteIndexEntry{Tutorial} |
| 6 | + %\VignetteEncoding{UTF-8} |
| 7 | + %\VignetteEngine{knitr::rmarkdown} |
| 8 | +editor_options: |
| 9 | + chunk_output_type: console |
| 10 | +--- |
| 11 | + |
| 12 | +```{r, include = FALSE} |
| 13 | +knitr::opts_chunk$set( |
| 14 | + collapse = TRUE, |
| 15 | + comment = "#>" |
| 16 | +) |
| 17 | +``` |
| 18 | + |
| 19 | +The package "kwb.package" has been developed when the KWB packages were not yet |
| 20 | +on GitHub but on KWB's internal Subversion server. That time, it was quite |
| 21 | +complicated to install KWB packages, especially when a package was depending |
| 22 | +on further KWB packages. Things got simpler when we moved our packages to |
| 23 | +GitHub and could use the `install_github()` function from the "remotes" package |
| 24 | +to install our packages. Nevertheless, "kwb.package" contains some useful |
| 25 | +functions about packages in general, such as functions to analyse or plot |
| 26 | +package dependencies. I will demonstrate the usage of some of these functions |
| 27 | +here. |
| 28 | + |
| 29 | +## Installation |
| 30 | + |
| 31 | +```{r eval = FALSE} |
| 32 | +# Install the latest "release" from our R-universe server |
| 33 | +install.packages("kwb.package", repos = "https://kwb-r.r-universe.dev") |
| 34 | +
|
| 35 | +# Install the development version from GitHub |
| 36 | +remotes::install_github("kwb-r/kwb.package@dev") |
| 37 | +``` |
| 38 | + |
| 39 | +## Cook Book Recipes |
| 40 | + |
| 41 | +### What packages does a package depend on? |
| 42 | + |
| 43 | +To find out what packages an R package depends on you may use the function `packageDependencies()`: |
| 44 | + |
| 45 | +```{r} |
| 46 | +# What packages does the package "ggplot2" depend on? |
| 47 | +# (including all sub-dependencies)? |
| 48 | +kwb.package::packageDependencies("ggplot2") |
| 49 | +
|
| 50 | +# What packages does the package "kwb.package" itself depend on? |
| 51 | +kwb.package::packageDependencies("kwb.package") |
| 52 | +
|
| 53 | +# Oops! |
| 54 | +
|
| 55 | +# What are the direct dependencies, without its sub-dependencies? |
| 56 | +kwb.package::packageDependencies("kwb.package", recursive = FALSE) |
| 57 | +``` |
| 58 | + |
| 59 | +### By what other (installed) packages a package is used? |
| 60 | + |
| 61 | +For a given package the function `packageDependencies()` can also find out |
| 62 | +what other (installed!) packages are depending on it. I am curious, for example |
| 63 | +which of my packages are depending on the "kwb.utils" package: |
| 64 | + |
| 65 | +```{r} |
| 66 | +kwb.package::packageDependencies("kwb.utils", reverse = TRUE) |
| 67 | +``` |
| 68 | + |
| 69 | +Quite a lot! |
| 70 | +Does the `recursive` argument (`TRUE` by default) make any difference here? |
| 71 | + |
| 72 | +```{r} |
| 73 | +kwb.package::packageDependencies("kwb.utils", reverse = TRUE, recursive = FALSE) |
| 74 | +``` |
| 75 | + |
| 76 | +No. Is it the case for other packages, e.g. the "dplyr" package? |
| 77 | + |
| 78 | +```{r} |
| 79 | +kwb.package::packageDependencies("dplyr", reverse = TRUE, recursive = TRUE) |
| 80 | +kwb.package::packageDependencies("dplyr", reverse = TRUE, recursive = FALSE) |
| 81 | +``` |
| 82 | + |
| 83 | +Yes. |
| 84 | + |
| 85 | +### How can I visualise package dependencies? |
| 86 | + |
| 87 | +```{r fig.width = 6, fig.height = 6, out.width = "60%"} |
| 88 | +packages <- c("wasserportal", "kwb.dwd") |
| 89 | +dependencies <- kwb.package::packageDependencies(packages, recursive = FALSE) |
| 90 | +par(mar = c(3, 0, 6, 0), xpd = TRUE) |
| 91 | +kwb.package::plotAllDependencies(dependencies, for.each = FALSE) |
| 92 | +``` |
| 93 | + |
| 94 | +There are some packages that are used by both, "wasserportal" and "kwb.dwd". |
0 commit comments