Packages that are needed
roxygen2 # In-Line Documentation for R
devtools # Tools to Make Developing R Packages Easier
testthat # Unit Testing for R
usethis # Automate Package and Project Setup
Idea
Name
Check for potential names
available::suggest(“Easily extract information about your sample”)
Check for potential names
available::available(“SyneosValid”, browse = FALSE)
To access the template, just click on
File > New Project… > New Directory > R Package.
Note, you need to check the box Create a git to set up a local git.
Hooray, you have started your own package! Let us take a look at the different files that were created.
.gitignore and .Rbuildignore contain documents that should be ignored when either building in git or R
DESCRIPTION gives the user all the core information about your package – we will talk more about this below.
man contains all manuals for your functions. You do not need to touch the .Rd files in there as they will be generated automatically once we populate our package with functions and run devtools::document().
NAMESPACE will later contain information on exported and imported functions. This file will not be modified by hand but we will show you how to do it automatically. This might seem counter-intuitive in the workflow, but we need to delete the NAMESPACE file here. We do this because we want NAMESPACE to be generated and to be accessible with the devtools universe. We will generate it automatically again later using the command devtools::document().
R contains all the functions that you create. We will address this folder and its files in the next step.
The overviewR.Rproj file is the usual R project file that you can read more about here.
Function documentation
title takes the name of your function
@description contains a short description
@param takes all your arguments that are in the input of the function with a short description. Our function has three arguments (dat (the data set), id (the scope), and time (the time period)).
@return gives the user information about the output of your function
@examples eventually provide a minimal working example for the user to see what s/he needs to include. You can also wrap \dontrun{} around your examples if they should not be executed (e.g., if additional software or an API key is missing). If this is not the case, it is not recommended to wrap this around as it will cause a warning for the user. If your example runs longer than 5 seconds, you can wrap \donttest{} around it.
@export – if this is a new package, it is always recommended to export your functions. It automatically adds these functions to the NAMESPACE file.
@importFrom dplyr "%>%" pre-defines required functions for your function. It automatically adds these functions to the NAMESPACE file.
Once you have included the preamble, you can now add your function below.
Fill your package with life Add functions Write a help file Write DESCRIPTION Add internal data set
Type: Package should remain unchanged Package has your package’s name | Title: is a really short description of your package Version has the version number (you will most likely start with a 0.0.1,
Authors@R contains the authors’ names and their roles. [cre] stands for the creator and this person is also the maintainer while [aut] is the author. There are also options to indicate a contributor ([ctb]) or translator ([trl]). At this point, you also need to give your e-mail address. If you want to submit your package to CRAN (but also in any other case), make sure that your e-mail address is correct and accessible!
Description: provides a longer description of what your package does. If you want to indent, use four blank spaces. | License shows others what they can do with your package. This is an important part and probably a tough decision. Here and here or here are excellent overviews of different licenses and a starting guide on how to pick the best one for you.
URL indicates where the package is currently hosted
BugReports show where users should address their reports to (if linked with GitHub, this will automatically refer the user to the issues section)
Depends shows the R version your package works with (you always need to indicate a version number!)
Imports shows the packages that are required to run your package (here you always need to indicate a version number so that potential conflicts with previous versions can be avoided!)
Suggests lists all the packages that you suggest but that are not necessarily required for the functionality of your package
…
LazyData: true ensures that internal data sets are automatically loaded when loading the package
Write the NEWS.md Write the vignette Check your package Write tests codecov —
Check whether it works on various operating systems with devtools and rhub Generate cran-comments.md file Continuous integration with GitHub Actions Checking for good practice I: goodpractice Checking for good practice II: inteRgrate Submit to CRAN —
Add-ons Create your own hexagon sticker Add badges Create your own manual Build your website for your package Write you own CheatSheet