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
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()
)
#> Pico package {mypkg} written to:
#> /var/folders/y5/ts9sjlt10x1d7qpkgbhy3smh0000gn/T//RtmpMmOHDt/mypkg
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")
)
#> checking for file ‘/private/var/folders/y5/ts9sjlt10x1d7qpkgbhy3smh0000gn/T/RtmpMmOHDt/file3dd21d3084a/mypkg/DESCRIPTION’ ... ✓ checking for file ‘/private/var/folders/y5/ts9sjlt10x1d7qpkgbhy3smh0000gn/T/RtmpMmOHDt/file3dd21d3084a/mypkg/DESCRIPTION’ (490ms)
#> ─ preparing ‘mypkg’:
#> ✓ checking DESCRIPTION meta-information
#> ─ checking for LF line-endings in source and make files and shell scripts
#> ─ checking for empty or unneeded directories
#> ─ creating default NAMESPACE file
#> ─ building ‘mypkg_0.0.9000.tar.gz’
#>
#>
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")
#> [1] "Ahoy-hoy Matthew!"
To add your own functions to the package:
- Paste your functions into
functions.R
and save - Re-run
install_local()
as above, but withforce = TRUE
to overwrite the old version - Restart R
The 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.