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)
Create a 'pico package': an R package with the minimum required structure and content.
{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 {pico} from GitHub with help from {remotes}:
install.packages("remotes") remotes::install_github("matt-dray/pico")
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() )
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 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")
To add your own functions to the package:
functions.R
and saveinstall_local()
as above, but with force = TRUE
to overwrite the old versionThe new functions will now be available from your package.
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")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.