Skip to contents

A function to setup a new personal package or update an existing package.

Usage

setup_package(path, packagename, core = NULL)

Arguments

path

The path in which the package shall be created. If it exists, it is used. If it does not exist, it is created, provided that the parent path exists.

packagename

The name of the newly generated package. It will be checked to make sure it meets R package naming conventions.

core

A vector or list containing package names that shall be attached when the newly generated package is loaded. The packages must be installed on the current system, otherwise an error will be shown.

Examples

# \donttest{
# create package "mypackage" in temporary directory with
# the core packages dplyr, glue and purrr
withr::with_tempdir({
  install.packages(
    c("dplyr", "glue", "purrr"),
    repos = "http://cran.us.r-project.org"
  )
  setup_package(
    path = tempdir(),
    packagename = "mypackage",
    core = c("dplyr", "glue", "purrr")
  )
})
#> Installing packages into ‘/home/runner/work/_temp/Library’
#> (as ‘lib’ is unspecified)
#>  Creating '/tmp/RtmpPHObRK/mypackage/'
#>  Setting active project to '/tmp/RtmpPHObRK/mypackage'
#>  Creating 'R/'
#>  Writing 'DESCRIPTION'
#> Package: mypackage
#> Title: What the Package Does (One Line, Title Case)
#> Version: 1.0.0
#> Authors@R (parsed):
#>     * First Last <first.last@example.com> [aut, cre] (YOUR-ORCID-ID)
#> Description: What the package does (one paragraph).
#> License: `use_mit_license()`, `use_gpl3_license()` or friends to
#>     pick a license
#> Encoding: UTF-8
#> Roxygen: list(markdown = TRUE)
#> RoxygenNote: 7.2.1
#>  Writing 'NAMESPACE'
#>  Setting active project to '<no active project>'
#>  Setting active project to '/tmp/RtmpPHObRK/mypackage'
#>  Writing 'R/mypackage-package.R'
#>  Writing 'README.md'
#>  Adding 'dplyr' to Imports field in DESCRIPTION
#>  Adding 'glue' to Imports field in DESCRIPTION
#>  Adding 'purrr' to Imports field in DESCRIPTION
#>  Adding 'cli' to Imports field in DESCRIPTION
#>  Adding 'crayon' to Imports field in DESCRIPTION
#>  Adding 'rstudioapi' to Imports field in DESCRIPTION
#>  Writing 'R/core.R'
#>  Writing 'R/attach.R'
#>  Writing 'R/conflicts.R'
#>  Writing 'R/pipe.R'
#>  Writing 'R/utils.R'
#>  Writing 'R/zzz.R'
#>  Updating documentation and installing mypackage...
#>  Loading mypackage
#> ── Attaching packages ─────────────────────────────────────── mypackage 1.0.0 ──
#>  dplyr 1.0.9      purrr 0.3.4
#>  glue  1.6.2     
#> ──────────────────────────────────────────────────────────────── Ready to go! ──
#> Writing NAMESPACE
#> Writing NAMESPACE
#> Writing mypackage-package.Rd
#> Writing pipe.Rd
#> Running /opt/R/4.2.1/lib/R/bin/R CMD INSTALL /tmp/RtmpPHObRK/mypackage \
#>   --install-tests 
#> * installing to library ‘/home/runner/work/_temp/Library’
#> * installing *source* package ‘mypackage’ ...
#> ** using staged installation
#> ** R
#> ** byte-compile and prepare package for lazy loading
#> ** help
#> *** installing help indices
#> ** building package indices
#> ** testing if installed package can be loaded from temporary location
#> ** testing if installed package can be loaded from final location
#> ** testing if installed package keeps a record of temporary installation path
#> * DONE (mypackage)
#>  Setting active project to '<no active project>'
# }