1 Guide to Building, Submitting, and Managing the zzlongplot R Package

1.1 Step 1: Setting Up the Package Structure

  1. Create a New Package Directory:
    • Use usethis to create a package directory:

      usethis::create_package("path/to/zzlongplot")
    • This sets up the necessary directory structure with folders like R/ and files like DESCRIPTION.

  2. Add the Core Script:
    • Place the zzlongplot.R file in the R/ directory.
  3. Set Up the DESCRIPTION File:
    • Edit the DESCRIPTION file to include metadata about the package. Use usethis::use_description() to create and fill this file:

      usethis::use_description(fields = list(
        Title = "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"
      ))
  4. Add Dependencies:
    • List package dependencies in the DESCRIPTION file under Imports. For example:

      Imports:
        dplyr,
        ggplot2,
        patchwork

1.2 Step 2: Document the Package

  1. Add Roxygen2 Comments:
    • Ensure all functions in zzlongplot.R have Roxygen2 comments for documentation.
  2. Generate Documentation:
    • Run:

      devtools::document()
    • This creates help files in the man/ directory and updates the NAMESPACE file.

  3. Create a Vignette:
    • Add the vignette to introduce the package:

      usethis::use_vignette("Introduction_to_zzlongplot")
    • Place the provided zzlongplot-vignette.Rmd file in the vignettes/ directory and build it:

      devtools::build_vignettes()

1.3 Step 3: Test the Package

  1. Add Unit Tests:
    • Use usethis to set up a testing framework:

      usethis::use_testthat()
    • Place the test-zzlongplot.R file in tests/testthat/.

  2. Run Tests:
    • Run all tests:

      devtools::test()

1.4 Step 4: Check the Package

  1. Build and Check:
    • Build the package:

      devtools::build()
    • Check the package for CRAN compliance:

      devtools::check()
  2. Fix Issues:
    • Address any warnings or errors reported by devtools::check().

1.5 Step 5: Submit to CRAN

  1. 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:

      devtools::build()
  2. Submit to CRAN:
  3. Respond to Feedback:
    • CRAN maintainers might request changes. Address them promptly and resubmit if needed.

1.6 Step 6: Set Up a GitHub Repository

  1. Initialize a Git Repository:
    • In the package directory, run:

      git init
      git add .
      git commit -m "Initial commit"
  2. Create a Repository on GitHub:
    • Use the GitHub website or the gh CLI tool:

      gh repo create yourusername/zzlongplot --public --source=.
  3. 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

  1. Add Version Control:
    • Use Git for version control. For example, create a branch for new features:

      git checkout -b feature-new-plot
  2. Tag Releases:
    • Tag versions for releases:

      git tag -a v0.1.0 -m "First release"
      git push origin v0.1.0
  3. Add Continuous Integration:
    • Set up GitHub Actions for testing:

      usethis::use_github_action_check_standard()
  4. Publish Development Versions:
    • Use GitHub to manage development versions and issues.

1.8 Step 8: Maintain the Package

  1. Address Issues:
    • Monitor and address issues reported by users.
  2. Update the Package:
    • For updates, increment the version number in DESCRIPTION and tag the new version.

Reuse

Citation

BibTeX citation:
@online{(ryy)_glenn_thomas,
  author = {(Ryy) Glenn Thomas, Ronald},
  url = {https://focusonr.org/posts/develop_r_package/zzlongplot-package-guide.html},
  langid = {en}
}
For attribution, please cite this work as:
(Ryy) Glenn Thomas, Ronald. n.d. https://focusonr.org/posts/develop_r_package/zzlongplot-package-guide.html.