createPackage: Create package from vector of source files and single...

View source: R/Rpackage.R

createPackageR Documentation

Create package from vector of source files and single configuration

Description

This function creates a package dir, runs documentation generation using roxygen and optionally installs the package. It can also update via git and manage version numbers. In a minimal configuration, a single file is sufficient to create a fully documented R package.

Usage

createPackage(
  packageDesc,
  packagesDir = "~/src/Rpackages",
  dir = NULL,
  doInstall = FALSE,
  doCheck = T,
  gitOptions = list(),
  noGit = F,
  lib = NULL,
  asCran = FALSE
)

Arguments

packageDesc

path to the configuration file (R, extended plist format, json, yaml). If an R-file is provided, it is sourced in a seperate environment and needs to define the variable 'packageDefinition'. This variable has to be a list which is further specified in the details below. If a propertyList/JSON/YAML-file is provided, they have to parse into a list corresponding to 'packageDefinition'. Functions propertyFromStringExt, read_json, and read_yaml are used for parsing, coming from packages package, jsonlite, and yaml.

packagesDir

folder in which the folder structure of the package is written

dir

directory to search for package definition

doInstall

flag to indicate whether the package should also be installed

doCheck

whether to run R CMD check –as-cran on the package

gitOptions

list with options for git interaction

noGit

boolean to suppress git calls, overwrites other options

lib

Path to package library as forwarded to install.packages

asCran

boolean to indicate whether check should be including –as-cran

Details

This function creates a valid R package folder with DESCRIPTION, LICENSE and NEWS files. All R-files listed are copied to this directory and documentation is created by running the devtools::document function on this folder. The package is specified through a list coming from an R script or configuration file. The following elements control package generation. In this list key1-key2 indicates a sublist-element, i.e. it stand for packageDefinition[[key1]][[key2]].

  • name: The name of the pacakge

  • files: R-files to be put into the package. If an R-file is used for the configuration, it will automatically be include. This allows package definition through a single R-file.

  • instFiles: Other files to be installed. This is a list, the names of which specify sub-folders in the inst sub-directory of the package. Values are character vectors specifying files to be put there.

  • description: A sub-list with elements specifying the DESCRIPTION file of the package.

  • description-title: The title of the help page 'package-myPackage' (myPackage is the name of the package) and the title fiedl in DESCRIPTION.

  • description-author: The Author field in DESCRIPTION.

    description-description: The Description field in DESCRIPTION. The text is re-used for the package documentation as displayed by ?'package-myPackage' and is prepended to the seperate package documentation. It is also inserted as a Description section of a Markdown file if git is used. This string should therefore not make use of roxygen/markdown markup.

  • description-depends: A character vector with package dependencies.

  • description-suggests: A character vector with package suggestions.

  • description-news: A character vector with a single element containing the NEWS file of the package. It is assumed that a line starting with a non white space character indicates a new version. The version identifier is taken to be all characters until the first white space. Once a new version is detected, git actions might be triggered (see below).

  • git: A sub-list specifying git behavior. If you do not want to use git, omit this entry from packageDefinition. If present, a git repository is created and maintained in the target folder. Default git settings for the package can be overwritten using the gitOptions argument.

  • git-push: Logical, whether to push each commit, defaults to FALSE.

  • git-pushOnNewVersion: Logical, whether to push each when a new release is created (see item description-news. Defaults to TRUE. A push is automatically performed, once a new release is created, irrespective of this setting. To suppress a push in these cases, push has to set to FALSE in the.

  • git-readme: Character vector with single entry with the content of a readme file that is put as README.md into the package main folder. The description given under description-description is appended to this text.

Author(s)

Stefan Böhringer, r-packages@s-boehringer.org

See Also

package-package

Examples


packageDefinition = list(
	name = 'pkg-minimal',
	files = c(),
instFiles = list(),
	description = list(
		title = 'Minimal R-package created with `package`',
		# version to be documented in news section
		#version = '0.1-0',
		author = 'Stefan Böhringer <r-packages@s-boehringer.org>',
		description = 'This appears in the package-documentaion, the markdown of the git-repository and in the package details.',
		depends = c(),
		suggests = c(),
		license = 'LGPL',
		news = "0.1-0	Initial release"
	),
	git = list(
		readme = '## Installation\n```{r}\nlibrary(devtools);\ninstall_github("user/pkg-minimal")\n```\n',
		push = FALSE,
		pushOnNewVersion = FALSE
	)
);



sboehringer/package documentation built on Jan. 12, 2023, 6:33 a.m.