Skip to content
/ pico Public

🔬📦 R package: generate the aboslute minimum R package skeleton

License

Notifications You must be signed in to change notification settings

matt-dray/pico

Repository files navigation

{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

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()
)
#> Pico package {mypkg} written to:
#>   /var/folders/y5/ts9sjlt10x1d7qpkgbhy3smh0000gn/T//RtmpMmOHDt/mypkg

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")
)
#>      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!"

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.

About

🔬📦 R package: generate the aboslute minimum R package skeleton

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Languages