1 Guide to Building, Submitting, and Managing the zzlongplot
R Package
1.1 Step 1: Setting Up the Package Structure
- Create a New Package Directory:
Use
usethis
to create a package directory:::create_package("path/to/zzlongplot") usethis
This sets up the necessary directory structure with folders like
R/
and files likeDESCRIPTION
.
- Add the Core Script:
- Place the
zzlongplot.R
file in theR/
directory.
- Place the
- Set Up the
DESCRIPTION
File:Edit the
DESCRIPTION
file to include metadata about the package. Useusethis::use_description()
to create and fill this file:::use_description(fields = list( usethisTitle = "Flexible Longitudinal Plotting in R", Description = "Provides tools for generating observed and change plots in longitudinal datasets.", Version = "0.1.0", Author = "Your Name [aut, cre]", Maintainer = "Your Name <your_email@example.com>", License = "MIT", Encoding = "UTF-8" ))
- Add Dependencies:
List package dependencies in the
DESCRIPTION
file underImports
. For example:Imports: dplyr, ggplot2, patchwork
1.2 Step 2: Document the Package
- Add Roxygen2 Comments:
- Ensure all functions in
zzlongplot.R
have Roxygen2 comments for documentation.
- Ensure all functions in
- Generate Documentation:
Run:
::document() devtools
This creates help files in the
man/
directory and updates theNAMESPACE
file.
- Create a Vignette:
Add the vignette to introduce the package:
::use_vignette("Introduction_to_zzlongplot") usethis
Place the provided
zzlongplot-vignette.Rmd
file in thevignettes/
directory and build it:::build_vignettes() devtools
1.3 Step 3: Test the Package
- Add Unit Tests:
Use
usethis
to set up a testing framework:::use_testthat() usethis
Place the
test-zzlongplot.R
file intests/testthat/
.
- Run Tests:
Run all tests:
::test() devtools
1.4 Step 4: Check the Package
- Build and Check:
Build the package:
::build() devtools
Check the package for CRAN compliance:
::check() devtools
- Fix Issues:
- Address any warnings or errors reported by
devtools::check()
.
- Address any warnings or errors reported by
1.5 Step 5: Submit to CRAN
- Prepare for Submission:
Ensure the package passes
R CMD check
with no warnings, errors, or notes.Compress the package into a
.tar.gz
file using:::build() devtools
- Submit to CRAN:
- Go to the CRAN submission page.
- Upload the
.tar.gz
file and fill out the required metadata.
- Respond to Feedback:
- CRAN maintainers might request changes. Address them promptly and resubmit if needed.
1.6 Step 6: Set Up a GitHub Repository
- Initialize a Git Repository:
In the package directory, run:
git init git add . git commit -m "Initial commit"
- Create a Repository on GitHub:
Use the GitHub website or the
gh
CLI tool:gh repo create yourusername/zzlongplot --public --source=.
- Push the Code:
Push the code to GitHub:
git branch -M main git push -u origin main
1.7 Step 7: Manage the Development Repository
- Add Version Control:
Use Git for version control. For example, create a branch for new features:
git checkout -b feature-new-plot
- Tag Releases:
Tag versions for releases:
git tag -a v0.1.0 -m "First release" git push origin v0.1.0
- Add Continuous Integration:
Set up GitHub Actions for testing:
usethis::use_github_action_check_standard()
- Publish Development Versions:
- Use GitHub to manage development versions and issues.
1.8 Step 8: Maintain the Package
- Address Issues:
- Monitor and address issues reported by users.
- Update the Package:
- For updates, increment the version number in
DESCRIPTION
and tag the new version.
- For updates, increment the version number in
Reuse
Citation
@online{(ryy)_glenn_thomas,
author = {(Ryy) Glenn Thomas, Ronald},
url = {https://focusonr.org/posts/develop_r_package/zzlongplot-package-guide.html},
langid = {en}
}