knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

# Remove dummy package if already installed
if (any(as.data.frame(installed.packages())$Package == "mypkg")) {
 remove.packages("mypkg")
}

# Attach {pico}
library(pico)

{pico}

Project Status: Concept – Minimal or no implementation has been done
yet, or the repository is only intended to be a limited example, demo,
or
proof-of-concept. R-CMD-check Codecov test coverage CodeFactor Blog post

Create a 'pico package': an R package with the minimum required structure and content.

What

{pico} is a toy package that generates the absolute bare-bones skeleton of an R package. It may be a useful teaching aid to demystify the perceived complexity of R packages, or a quick-start to create a package of your often-used personal functions. Read more in the accompanying blog post.

Click for (free) resources for 'proper' package-writing Hilary Parker’s Writing an R Package from Scratch post Tom Westlake’s update to Hilary’s post Fabio Votta's fun slides I wrote some slides about {usethis} for package development Emil Hvitfeldt’s {usethis} workflow Karl Broman’s R Package Primer site * Hadley Wickham’s R Packages book

Install

Install {pico} from GitHub with help from {remotes}:

install.packages("remotes")
remotes::install_github("matt-dray/pico")

Example

Create

Use the create() function to generate a 'pico package' in a specified location with the minimum required content. For example, to create {mypkg} in a temporary folder:

pico::create(
 name = "mypkg",
 dir = tempdir()
)

Structure

At your specified path, you'll get the minimum required package structure:

mypkg/
├── R/
│   └── functions.R
└── DESCRIPTION

The R/ directory has the script file functions.R, pre-filled with the dummy function say_hi(). The DESCRIPTION text-file is a special file that earmarks the directory as an R package. It contains only the name and version number of the package.

Install

Install the package from your machine (i.e. it's 'local' to you) with install_local() from {remotes}:

remotes::install_local(
 path = file.path(tempdir(), "mypkg")
)

The package is now installed into your R package library and can be attached like any other package.

library(mypkg)

Now you can use the provided dummy function say_hi():

say_hi("Matthew")

Develop

To add your own functions to the package:

  1. Paste your functions into functions.R and save
  2. Re-run install_local() as above, but with force = TRUE to overwrite the old version
  3. Restart R

The new functions will now be available from your package.

Code of Conduct

Please note that the {pico} project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

# Tidy up
unlink(file.path(tempdir(), "mypkg"), recursive = TRUE)
remove.packages("mypkg")


matt-dray/pico documentation built on Dec. 21, 2021, 2:54 p.m.