Package dependencies

Developing R Packages

Jasmin Ludolf

Content Developer

R package structure

R package skeleton

Developing R Packages

Three types of dependencies

  1. Imports:
    • Required
    • Allows functions in our package to work properly
    • Automatically loaded

Imports box

Developing R Packages

Three types of dependencies

  1. Imports:

    • Required
    • Allows functions in our package to work properly
    • Automatically loaded
  2. Suggests:

    • Not required
    • Additional functionality

Imports box

Suggests lightbulb

Developing R Packages

Three types of dependencies

  1. Imports:

    • Required
    • Allows functions in our package to work properly
    • Automatically loaded
  2. Suggests:

    • Not required
    • Additional functionality
  3. Depends:

    • Attaches the dependency
    • Rarely used

Imports box

Suggests lightbulb

Depends question mark

Developing R Packages

Add CRAN package as dependency

  • Add stringr as package to Imports
library(usethis)
use_package("stringr", type = "Imports")

stringr import output

In DESCRIPTION file

Imports: 
    stringr
Developing R Packages

Set minimum package version as dependency

usethis::use_package("stringr", min_version = "1.4.0")

stringr import output

In DESCRIPTION file

Imports: 
    stringr (>= 1.4.0)
Developing R Packages

Using use_package() for Suggests

use_package("tibble", type = "Suggests")

tibble Suggests output

Developing R Packages

Using use_package() for Depends

use_package("glue", type = "Depends")

glue Depends output

Developing R Packages

Revisiting DESCRIPTION - first part

Package: unitConverter
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R: 
    person("First", "Last", , "[email protected]", role = c("aut", "cre"),
           comment = c(ORCID = "YOUR-ORCID-ID"))
Description: What the package does (one paragraph).
License: MIT
Encoding: UTF-8
...
Developing R Packages

Revisiting DESCRIPTION - second part

...
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Depends: 
    R (>= 2.10)
LazyData: true
Imports: 
    stringr (>= 1.4.0)
Suggests: 
    tibble
Depends:
    glue
Developing R Packages

Let's practice!

Developing R Packages

Preparing Video For Download...