Package 'kwb.pkgbuild'

Title: R package for standardised development at KWB
Description: Helper functions for automating R package development at KWB to a predefined style.
Authors: Michael Rustler [aut, cre] , Hauke Sonnenberg [aut] , FAKIN [fnd], Kompetenzzentrum Wasser Berlin gGmbH (KWB) [cph]
Maintainer: Michael Rustler <[email protected]>
License: MIT + file LICENSE
Version: 0.2.3
Built: 2024-11-14 04:29:50 UTC
Source: https://github.com/KWB-R/kwb.pkgbuild

Help Index


Copy files from Vignettes Dir to Deploy idir

Description

Copy files from Vignettes Dir to Deploy idir

Usage

copy_files_from_vignettes_dir_to_deploy_dir(
  source_dir = ".",
  deploy_dir = "docs",
  pattern = "\\.json$",
  overwrite = TRUE
)

Arguments

source_dir

default: "."

deploy_dir

default: "docs

pattern

file pattern to export (default: "\.json$")

overwrite

should existing files be overwritten (default: TRUE)

Value

files matching pattern copied to deploy_dir


Create Empty Branch From Github

Description

Create Empty Branch From Github

Usage

create_empty_branch(
  repo = NULL,
  branch = NULL,
  org = "KWB-R",
  set_githubuser = TRUE,
  git_exe = path_to_git(),
  dest_dir = tempdir(),
  execute = TRUE,
  dbg = TRUE,
  ...
)

Arguments

repo

name of existing Github repository (default: NULL)

branch

name of branch to be created (default: NULL)

org

repo owner (default: "KWB-R")

set_githubuser

should the Github user be set before executing the branch creation (default: TRUE). In this case set_github_user() is run

git_exe

path to GIT executable (default: kwb.pkgbuild:::path_to_git()), only required on "windows". On all other platforms it is assumed that "git" is sufficient!

dest_dir

directory where the the repo should be checked out (default: tempdir())

execute

should a batch file be run?

dbg

print debug messages (default: TRUE)

...

additional arguments passed to set_github_user

Value

create empty branch (defined in 'branch') and push to org/repo on Github


Create Empty gh-pages branch

Description

Create Empty gh-pages branch

Usage

create_empty_branch_ghpages(
  repo = NULL,
  org = "KWB-R",
  set_githubuser = TRUE,
  git_exe = path_to_git(),
  dest_dir = tempdir(),
  execute = TRUE,
  dbg = TRUE,
  ...
)

Arguments

repo

name of existing Github repository (default: NULL)

org

repo owner (default: "KWB-R")

set_githubuser

should the Github user be set before executing the branch creation (default: TRUE). In this case set_github_user() is run

git_exe

path to GIT executable (default: kwb.pkgbuild:::path_to_git()), only required on "windows". On all other platforms it is assumed that "git" is sufficient!

dest_dir

directory where the the repo should be checked out (default: tempdir())

execute

should a batch file be run?

dbg

print debug messages (default: TRUE)

...

additional arguments passed to set_github_user

Value

create and push an empty gh-pages branch to org/repo


Create Package Directory

Description

Create Package Directory

Usage

create_pkg_dir(pkg_dir)

Arguments

pkg_dir

path to package directory to be created, including the pkgname as last folder

Value

creates directory for package if not existing

Examples

## not a valid pkg folder
## Not run: 
pkg_dir <- file.path(tempdir(), "pkgname/pkgname")
create_pkg_dir(pkg_dir)

## End(Not run)
## valid pkg folder
pkg_dir <- file.path(tempdir(), "pkgname")
create_pkg_dir(pkg_dir)

deploy_site_github_with_extra_files

Description

for details see pkgdown::deploy_site_github(), only parameter vignettes_file_pattern_to_copy added

Usage

deploy_site_github_with_extra_files(
  pkg = ".",
  vignettes_file_pattern_to_copy = "\\.json$",
  install = TRUE,
  tarball = Sys.getenv("PKG_TARBALL", ""),
  ssh_id = Sys.getenv("id_rsa", ""),
  commit_message = construct_commit_message(pkg),
  clean = FALSE,
  verbose = TRUE,
  host = "github.com",
  repo_slug = Sys.getenv("TRAVIS_REPO_SLUG", ""),
  ...
)

Arguments

pkg

"."

vignettes_file_pattern_to_copy

file patern for copying files from vignettes directory into deploy directory (default: "\.json$")

install

Optionally, opt-out of automatic installation. This is necessary if the package you're documenting is a dependency of pkgdown

tarball

tarball Sys.getenv("PKG_TARBALL", "")

ssh_id

ssh_id Sys.getenv("id_rsa", "")

commit_message

commit_message (default: construct_commit_message(pkg))

clean

Clean all files from old site (default: FALSE)

verbose

Print verbose output (default: TRUE)

host

The GitHub host url (default: "github.com")

repo_slug

The 'user/repo' slug for the repository.

...

additional arguments passed to [deploy_to_branch_with_extra_files]

Value

deploy pkgdown site including additional files in "vignettes" source folder to "gh-pages"


Build and deploy a site locally with extra files

Description

Assumes that you're in a git clone of the project, and the package is already installed.

Usage

deploy_to_branch_with_extra_files(
  pkg = ".",
  vignettes_file_pattern_to_copy = "\\.json",
  commit_message = construct_commit_message(pkg),
  clean = FALSE,
  branch = "gh-pages",
  remote = "origin",
  github_pages = (branch == "gh-pages"),
  ...
)

Arguments

pkg

"."

vignettes_file_pattern_to_copy

file patern for copying files from vignettes directory into deploy directory (default: "\.json$")

commit_message

commit_message (default: construct_commit_message(pkg))

clean

Clean all files from old site (default: FALSE)

branch

The git branch to deploy to

remote

The git remote to deploy to

github_pages

Is this a GitHub pages deploy. If 'TRUE', adds a 'CNAME' file for custom domain name support, and a '.nojekyll' file to suppress jekyll rendering.

...

Additional arguments passed to pkgdown::build_site()


Helper Function: Get Package Name

Description

Helper Function: Get Package Name

Usage

get_pkgname(pkgname = NULL)

Arguments

pkgname

either package name or NULL. In this case the DESCRIPTION file in the current working directory is read and is package name ues (default: NULL)

Value

package name


Git Check Configuration

Description

Git Check Configuration

Usage

git_check_config(git_exe = path_to_git())

Arguments

git_exe

path to git executable on Windows (default: path_to_git())

Value

prints 'global' and 'local' Git configuration

Examples

## Not run: 
git_check_config()

## End(Not run)

Git Setup User (Name and Email)

Description

Git Setup User (Name and Email)

Usage

git_setup_user(
  github_username,
  github_email,
  scope = c("local", "global"),
  git_exe = path_to_git()
)

Arguments

github_username

username should be your GitHub username

github_email

email should be identical to email you registered with at GitHub (e.g. your.name(at)kompetenz-wasser.de)

scope

scope (default: c("local", "global"))

git_exe

path to git executable on Windows (default: path_to_git())

Value

runs "git" to setup the Git(Hub) user

See Also

<https://support.rstudio.com/hc/en-us/community/posts/115001143667-Author-Change-with-Git-in-RStudio>

Examples

## Not run: 
git_setup_user("mrustl", "[email protected]")

## End(Not run)

Helper function: read_description

Description

Helper function: read_description

Usage

read_description(file = "DESCRIPTION")

Arguments

file

path to DESCRIPTION file (default: DESCRIPTION)

Value

list with pkg "name", "title", "desc", "version"


Set Github User For GIT

Description

Set Github User For GIT

Usage

set_github_user(
  git_username = "kwb.pkgbuild::use_autopkgdown()",
  git_fullname = "kwb.pkgbuild::use_autopkgdown()",
  git_email = "[email protected]",
  git_exe = path_to_git(),
  execute = FALSE,
  execute_dir = tempdir(),
  dbg = TRUE
)

Arguments

git_username

Github username (default: "kwb.pkgbuild::use_autopkgdown()")

git_fullname

Github fullname (default: "kwb.pkgbuild::use_autopkgdown()")

git_email

(default: '[email protected]'), is then internally derived by calling whoami::fullname() and assuming that Github "kompetenz-wasser.de" used as email on Github

git_exe

path git git executable (only used on Windows as it is not installed in the local "environment"). On all other plattforms it is assumed that a call with "git" works

execute

should a batch file be run?

execute_dir

path to directory where batch script should be run in case that execute == TRUE (default: tempdir())

dbg

print debug messages (default: TRUE)

Value

sets globally user.name and user.email in Git


Use Auto Pkgdown

Description

automate pkgdown::build_site by running it on Travis and deploying to gh-pages branch

Usage

use_autopkgdown(
  repo = NULL,
  org = "KWB-R",
  set_githubuser = TRUE,
  git_exe = path_to_git(),
  dest_dir = tempdir(),
  execute = TRUE,
  dbg = TRUE,
  ...
)

Arguments

repo

name of existing Github repository (default: NULL)

org

repo owner (default: "KWB-R")

set_githubuser

should the Github user be set before executing the branch creation (default: TRUE). In this case set_github_user() is run

git_exe

path to GIT executable (default: kwb.pkgbuild:::path_to_git()), only required on "windows". On all other platforms it is assumed that "git" is sufficient!

dest_dir

directory where the the repo should be checked out (default: tempdir())

execute

should a batch file be run?

dbg

print debug messages (default: TRUE)

...

additional arguments passed to set_github_user

Value

workflow required for automating pkgdown::build_site() on Travis


Badge appveyor

Description

Badge appveyor

Usage

use_badge_appveyor(repo = NULL, user = "KWB-R", domain = "github")

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

domain

under which repository is hosted (default: "github")

Value

generates appveyor badge link


Badge codecov

Description

Badge codecov

Usage

use_badge_codecov(repo = NULL, user = "KWB-R", domain = "github")

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

domain

under which repository is hosted (default: "github")

Value

generates codecov badge link


Badge CRAN

Description

Badge CRAN

Usage

use_badge_cran(pkgname = NULL)

Arguments

pkgname

name of R package (default: NULL)

Value

generates CRAN badge link


Badge Github Actions

Description

Badge Github Actions

Usage

use_badge_ghactions(repo = NULL, user = "KWB-R", branch = NULL)

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

branch

default: NULL (i.e. use "default" branch) or user defined branch (e.g. "dev")

Value

generates Github Actions badges link


Badge Github Actions Pkgdown

Description

Badge Github Actions Pkgdown

Usage

use_badge_ghactions_pkgdown(repo = NULL, user = "KWB-R", branch = NULL)

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

branch

default: NULL (i.e. use "default" branch) or user defined branch (e.g. "dev")

Value

generates Github Actions Pkgdown badge link


Badge Github Actions RCMD Check

Description

Badge Github Actions RCMD Check

Usage

use_badge_ghactions_rcmdcheck(repo = NULL, user = "KWB-R", branch = NULL)

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

branch

default: NULL (i.e. use "default" branch) or user defined branch (e.g. "dev")

Value

generates travis badge link


Badge lifecycle

Description

Badge lifecycle

Usage

use_badge_lifecycle(stage = "experimental")

Arguments

stage

badge declares the developmental stage of a package, according to [https://www.tidyverse.org/lifecycle/](https://www.tidyverse.org/lifecycle/), valid arguments are: "experimental", "maturing", "stable", "retired", "archived", "dormant", "questioning"), (default: "experiment")

Value

generates lifecycle badge link


Badge R-Universe

Description

Badge R-Universe

Usage

use_badge_runiverse(repo = NULL, user = "KWB-R")

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

Value

generates codecov badge link


Badge travis

Description

Badge travis

Usage

use_badge_travis(repo = NULL, user = "KWB-R")

Arguments

repo

name of repository (default: NULL)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: KWB-R")

Value

generates travis badge link


Adds codecov.yml

Description

Adds codecov.yml

Usage

use_codecov()

Value

writes codecov.yml and adds it .Rbuildignore


Use DESCRIPTION with KWB styling

Description

Use DESCRIPTION with KWB styling

Usage

use_description(
  author = kwb_author("rustler"),
  pkg = kwb_package("kwb.umberto"),
  version = NULL,
  license = "MIT + file LICENSE",
  copyright_holder_name = kwb_string(),
  funder = NULL
)

Arguments

author

author information in list format (default: kwb.pkgbuild:::kwb_author("rustler"))

pkg

package description in list format (default: kwb.pkgbuild:::kwb_package("kwb.umberto"))

version

user defined version number (e.g. 0.1.0) or default version number 0.0.0.9000 in case (version = NULL) of first release

license

license (default: "MIT + file LICENSE")

copyright_holder_name

name of copyright holder (default: kwb.pkgbuild:::kwb_string())

funder

funder/funding agency of R package (default: NULL), e.g. project name (e.g. AQUANES)

Value

writes DESCRIPTION file using usethis::use_description() with KWB style


Adds default .github/workflows/

Description

Adds default .github/workflows/

Usage

use_ghactions()

Value

writes .github/workflows/ and adds it .Rbuildignore


Adds .gitlab-ci.yml (if repo contains on root in a "gh-pages" branch)

Description

Adds .gitlab-ci.yml (if repo contains on root in a "gh-pages" branch)

Usage

use_gitlab_ci_blogdown(
  dest_dir = getwd(),
  yml_vector = gitlab_ci_template_blogdown()
)

Arguments

dest_dir

directoy to write (default: getwd())

yml_vector

a yml imported as string vector (default: gitlab_ci_template_blogdown())

Value

writes .gitlab-ci.yml


Adds .gitlab-ci.yml (if repo contains a "docs" subfolder)

Description

Adds .gitlab-ci.yml (if repo contains a "docs" subfolder)

Usage

use_gitlab_ci_docs(dest_dir = getwd(), yml_vector = gitlab_ci_template_docs())

Arguments

dest_dir

directoy to write (default: getwd())

yml_vector

a yml imported as string vector (default: gitlab_ci_template_docs())

Value

writes .gitlab-ci.yml and adds it .Rbuildignore


Adds .gitlab-ci.yml (which should be saved in root dir of "gh-pages" branch)

Description

Adds .gitlab-ci.yml (which should be saved in root dir of "gh-pages" branch)

Usage

use_gitlab_ci_ghpages(
  dest_dir = getwd(),
  yml_vector = gitlab_ci_template_ghpages()
)

Arguments

dest_dir

directoy to write (default: getwd())

yml_vector

a yml imported as string vector (default: gitlab_ci_template_ghpages())

Value

writes .gitlab-ci.yml


Adds .gitlab-ci.yml

Description

Adds .gitlab-ci.yml

Usage

use_gitlab_ci_pkgdown(
  dest_dir = getwd(),
  yml_vector = gitlab_ci_template_pkgdown()
)

Arguments

dest_dir

directoy to write (default: getwd())

yml_vector

a yml imported as string vector (default: gitlab_ci_template_pkgdown(), where "<owner>/<repo>" is replaced with value from DESCRIPTION specified in field URL, e.g. https://github.com/KWB-R/kwb.pkgbuild" sets "KWB-R/kwb.pkgbuild" as "<owner>/<repo>")

Value

writes .gitlab-ci.yml


Use index.md (used for pkgdown::build_home())

Description

Use index.md (used for pkgdown::build_home())

Usage

use_index_md(user = "KWB-R", domain = "github", stage = "experimental")

Arguments

user

user name or organisation under which repository defined in
parameter "repo" is hosted (default: "KWB-R")

domain

under which repository is hosted (default: "github")

stage

badge declares the developmental stage of a package, according to [https://www.tidyverse.org/lifecycle/](https://www.tidyverse.org/lifecycle/), valid arguments are: "experimental", "maturing", "stable", "retired", "archived", "dormant", "questioning"), (default: "experiment")

Value

generates travis badge link


Helper function: describe pkg installation in index.Rmd / README.md

Description

Helper function: describe pkg installation in index.Rmd / README.md

Usage

use_installation(pkgname, user, domain)

Arguments

pkgname

package name

user

user name or organisation under which repository defined in parameter "repo" is hosted

domain

under which repository is hosted


Create MIT licence with KWB style

Description

Create MIT licence with KWB style

Usage

use_mit_license(
  copyright_holder = list(name = kwb_string(), start_year = NULL)
)

Arguments

copyright_holder

list with name of copyright holder and additional start_year (e.g. "2017") of copyright protection. If not specified (start_year = NULL), the current year is used as year only! (default: "list(name = kwb.pkgbuild:::kwb_string(), start_year = NULL)")

Value

creates MIT licence file


Create KWB-styled "NEWS.md"

Description

Create KWB-styled "NEWS.md"

Usage

use_news_md(
  news_txt = "* Added a `NEWS.md` file to track changes to the package.",
  style_guide_url = "https://style.tidyverse.org/news.html"
)

Arguments

news_txt

text added to news (default: "* Added a 'NEWS.md' file to track changes to the package.")

style_guide_url

refer to tidyverse style website documenting how to write a good "NEWS.md"(default: "https://style.tidyverse.org/news.html")

Value

writes "NEWS.md" (in case it is not existing)


Wrapper function for preparing R package with KWB styling

Description

Wrapper function for preparing R package with KWB styling

Usage

use_pkg(
  author = kwb_author("rustler"),
  pkg = kwb_package("kwb.umberto"),
  version = "0.0.0.9000",
  license = "MIT + file LICENSE",
  copyright_holder = list(name = kwb_string(), start_year = NULL),
  funder = NULL,
  user = "KWB-R",
  domain = "github",
  stage = "experimental",
  auto_build_pkgdown = FALSE,
  dbg = TRUE,
  ...
)

Arguments

author

author information in list format (default: kwb.pkgbuild:::kwb_author("rustler"))

pkg

package description in list format (default: kwb.pkgbuild:::kwb_package("kwb.umberto"))

version

user defined version number (e.g. 0.1.0) or default "0.0.0.9000" version number for initial development version (default: "0.0.0.9000")

license

license (default: "MIT + file LICENSE")

copyright_holder

list with name of copyright holder and additional start_year (e.g. "2017") of copyright protection. If not specified (start_year = NULL), the current year is used as year only! (default: "list(name = kwb.pkgbuild:::kwb_string(), start_year = NULL)")

funder

funder/funding agency of R package (default: NULL), e.g. project name (e.g. AQUANES)

user

user name or organisation under which repository defined in parameter "repo" is hosted (default: "KWB-R")

domain

under which repository is hosted (default: "github")

stage

badge declares the developmental stage of a package, according to [https://www.tidyverse.org/lifecycle/](https://www.tidyverse.org/lifecycle/), valid arguments are: "experimental", "maturing", "stable", "retired", "archived", "dormant", "questioning"), (default: "experiment")

auto_build_pkgdown

prepare Travis for pkgdown::build_site() (default: FALSE), only possible if GITHUB repo already existing

dbg

print debug messages (default: TRUE)

...

additional arguments passed to use_autopkgdown() (only releveant if "auto_build_pkgdown" == TRUE)

Value

writes DESCRIPTION file using usethis::use_description() with KWB style


Use Package Skeleton

Description

Use Package Skeleton

Usage

use_pkg_skeleton(pkg_name)

Arguments

pkg_name

name of R package

Value

creates pkg skeleton in current working directory

Examples

## valid pkg folder
pkg_name <- "pkgname"
pkg_dir <- file.path(tempdir(), pkg_name)
pkg_dir <- create_pkg_dir(pkg_dir)
withr::with_dir(pkg_dir, {use_pkg_skeleton(pkg_name)})

pkgdown for KWB

Description

pkgdown for KWB

Usage

use_pkgdown(
  author = kwb_author("rustler"),
  copyright_holder_name = kwb_string(),
  pkg = get_pkgname(),
  user = "kwb-r",
  domain = "github"
)

Arguments

author

list of author attributes (default: kwb.pkgbuild:::kwb_author("rustler"))

copyright_holder_name

name of copyright holder (default: kwb.pkgbuild:::kwb_string())

pkg

name of KWB package (default: get_pkgname())

user

name of GitHub user/organisation (default: 'kwb-r')

domain

name of domain for webpage publishing (default: 'github')

Value

performs usethis::use_pkgdown() and additionally writes _pkgdown.yml based on KWB styling


Use README

Description

Use README

Usage

use_readme_md(user = "KWB-R", domain = "github", stage = "experimental")

Arguments

user

user name or organisation under which repository defined in
parameter "repo" is hosted (default: "KWB-R")

domain

under which repository is hosted (default: "github")

stage

badge declares the developmental stage of a package, according to [https://www.tidyverse.org/lifecycle/](https://www.tidyverse.org/lifecycle/), valid arguments are: "experimental", "maturing", "stable", "retired", "archived", "dormant", "questioning"), (default: "experiment")

Value

generates README.md


Write to .gitignore

Description

Write to .gitignore

Usage

write_to_gitignore(ignore_pattern, comment = NULL)

Arguments

ignore_pattern

pattern that should be added to .Rbuildignore

comment

optional comment to write to file before the ignore pattern #' (default: NULL)

Value

.gitignore created/updated with pattern


Write to .Rbuildignore

Description

Write to .Rbuildignore

Usage

write_to_rbuildignore(ignore_pattern, comment = NULL)

Arguments

ignore_pattern

pattern that should be added to .Rbuildignore

comment

optional comment to write to file before the ignore pattern (default: NULL)

Value

.Rbuildignore created/updated with pattern