all(c("devtools", "roxygen2", "testthat", "knitr", "pkgdown") %in% installed.packages())
Package Creation and Metadata π§°
Get Ready
Check required packages
Check development toolchain and git
library(devtools)
has_devel()
Lay the foundations
Load devtools and create your package infrastructure
library(devtools)
create_package("~/Desktop/libminer")
Confirm git is configured correctly (and update if necessary)
This should have been done in your setup, but itβs not a bad idea to double check.
git_sitrep()
If the above command returns unsatisfactory information (most importantly, do you have a username and email configured), run the following command to configure git:
use_git_config(
user.name = "Your Name",
user.email = "Your Email"
)
Initialize this package as a git repo
use_git()
Use devtools
We can load devtools automatically via our .Rprofile
file so that it is always loaded during development
use_devtools()
Paste the contents of your clipboard in .Rprofile
, and restart R.
Write your first function
Open a new file in R/
to hold your code
use_r("lib-summary")
Write your function definition in this file
<- function() {
lib_summary <- utils::installed.packages()
pkgs <- table(pkgs[, "LibPath"])
pkg_tbl <- as.data.frame(pkg_tbl, stringsAsFactors = FALSE)
pkg_df names(pkg_df) <- c("Library", "n_packages")
pkg_df }
Load your package with load_all()
load_all()
And test out our new function:
lib_summary()
Library n_packages
1 /home/runner/work/_temp/Library 95
2 /opt/R/4.3.1/lib/R/library 29
3 /opt/R/4.3.1/lib/R/site-library 1
Check your package
check()
Set a license
use_mit_license()
DESCRIPTION file:
Package: libminer
Title: Explore Your R Libraries
Version: 0.0.0.9000
Authors@R:
person("Jane", "Doe",
email = "jane.doe@something.com",
role = c("aut", "cre"),
comment = c(ORCID = "XXXX-XXXX-XXXX-XXXX"))
Description: Provides functions for learning about your R libraries, and the
packages you have installed.
Check again
check()
Use GitHub
use_github()
Set a default DESCRIPTION
This avoids having to do this manually every time
edit_r_profile()
And add this to your .Rprofile
file
# Set usethis options:
options(
usethis.description = list(
"Authors@R" = utils::person(
"Jame", "Doe",
email = "jane.doe@example.com",
role = c("aut", "cre"),
comment = c(ORCID = "0000-1111-2222-3333")
)
)
)
options(
warnPartialMatchArgs = TRUE,
warnPartialMatchDollar = TRUE,
warnPartialMatchAttr = TRUE
)