Start here
pkgmkr helps you create a new R package without doing
the same setup by hand every time.
It can be used for a quick one-time setup or with a config file you reuse for future packages.
Create a package with one function call
Start with mk_pkg() if you want a new package with the
main setup files.
library(pkgmkr)
mk_pkg(
path = "mypackage",
author = "Jane Doe",
email = "jane.doe@example.com",
git = FALSE,
check_pkg_name = FALSE,
pkgdown = FALSE
)This creates a package called mypackage in your current
working directory.
What the main arguments do
-
pathsets the package folder name or full path. -
authoris the author name. It must include a first and last name. -
emailis optional. If you include it, it is added to the package metadata. -
gitcontrols whether a Git repository is initialized. -
check_pkg_namecontrols whetherpkgmkrchecks if the package name is available using theavailablepackage. -
pkgdowncontrols whether a pkgdown site is set up and built.
What gets created when you run mk_pkg()
pkgmkr handles the basic setup so you can start writing
code sooner.
After a successful run, your package will include the main files you would usually make by hand:
-
DESCRIPTIONfor package metadata -
NAMESPACEfor exported functions -
R/for your package code -
man/for generated documentation - license files based on your selected license
-
README.mdifreadme_md = TRUE - Git setup if
git = TRUE - pkgdown setup if
pkgdown = TRUE
Use options when you need more control
You do not need every argument the first time. Start small, then add options when you need them.
For example, if you want Git and pkgdown from the start:
mk_pkg(
path = "~/projects/myanalysispkg",
author = "Jane Doe",
email = "jane.doe@example.com",
git = TRUE,
git_username = "janedoe",
git_email = "jane.doe@example.com",
license = "GPL-3",
pkgdown = TRUE
)Use this when you already want Git and a pkgdown site.
Create a reusable package template with a config file
If you make packages often, keep one config file with your usual settings. Then you can reuse it instead of typing the same values each time.
mk_pkg_from_config() expects a YAML or JSON file with at
least these required fields:
pkg_namefirst_namelast_name
You can also include optional fields like email,
git, license, check_pkg_name,
readme_md, and pkgdown.
Example YAML config
Save a file such as standard-package.yml:
pkg_name: mypackage
first_name: Jane
last_name: Doe
email: jane.doe@example.com
readme_md: true
git: false
check_pkg_name: true
license: MIT
pkgdown: falseThis gives you a reusable template. For most new packages, you only
need to change pkg_name.
Create the package from the YAML file
mk_pkg_from_config("standard-package.yml", file_type = "yaml")This helps you keep package setup consistent across projects.
If you want to generate the YAML file from R instead of writing it by
hand, use write_config().
standard_config <- list(
pkg_name = "mypackage",
first_name = "Jane",
last_name = "Doe",
email = "jane.doe@example.com",
readme_md = TRUE,
git = FALSE,
check_pkg_name = TRUE,
license = "MIT",
pkgdown = FALSE
)
write_config("standard-package.yml", standard_config)Know the built-in validation rules
pkgmkr checks common inputs before it creates the
package. This helps catch problems early.
- Package names must start with a letter.
- Package names can contain only letters, numbers, and dots.
- Package names cannot end with a dot.
- Author names must include at least a first and last name.
- Email addresses must be valid if provided.
- Licenses must currently be
MITorGPL-3. - The target directory must not already exist.
Next steps
After the package is created, a common next step is:
- Add functions in
R/. - Document them with roxygen comments.
- Run
devtools::document(). - Add tests under
tests/. - Build or refine your pkgdown site if you enabled it.
Learn more
- Browse the reference documentation for more details.
- See examples for
mk_pkg(). - See configuration helpers for the config-file workflow.