Skip to Content
Course content

72: Submitting a Package to CRAN

Click on the "Edit" button in the top corner of the screen to edit your slide content.

I remember the first time I submitted a package to CRAN. I had spent weeks polishing my code, documenting every single function, and running devtools::check() until I saw nothing but "OK" in my console. I felt invincible. I hit the submit button and waited. About twenty-four hours later, I got an email from a CRAN maintainer. It wasn't a congratulatory note; it was a detailed list of failures on a specific version of Windows and a warning about a missing dependency in my DESCRIPTION file that I'd somehow overlooked. My package worked perfectly on my Mac, but in the real world—the diverse, fragmented world of CRAN—it was broken. That's the moment I realized that local checks are just the beginning; the real test is the CRAN gauntlet.

Perfecting the local check before the plunge

Before you even think about hitting submit, you need to be obsessed with R CMD check. You've used devtools::check() in previous lessons, but when you're aiming for CRAN, "mostly clean" isn't enough. You are looking for zero errors and, ideally, zero warnings. Notes are often acceptable, but they are a signal that something is slightly off—maybe a missing documentation link or a deprecated function call. I usually spend a few days just hunting down every single "Note" simply because it makes the maintainer's job easier, and a happy maintainer is a faster maintainer.

One thing that catches people off guard is the DESCRIPTION file. CRAN is incredibly strict about this. If your License field isn't exactly right, or if you've listed a package in Imports that should actually be in Suggests, your package will be rejected. Make sure your URL and BugReports fields are populated; CRAN wants to know where the code lives and how users can report issues. It sounds like bureaucracy, but it's what keeps the R ecosystem from collapsing into a mess of orphaned, undocumented code.

Navigating the submission and review cycle

Once your local checks are pristine, you can use devtools::submit_cran(). This handles the heavy lifting of bundling your package and sending it to the CRAN servers. But here is the part they don't tell you in the documentation: the waiting game is the hardest part. You'll likely receive an automated email confirming receipt, and then... silence for a few days.

When the maintainer finally replies, don't take the critique personally. If they tell you that your function calculate_flux() fails on a certain OS, don't reply with "It works on my machine." That is the fastest way to annoy a maintainer. Instead, treat it as a bug report. Fix the issue, run the check again locally, and reply with a clear explanation of what you changed. I've found that being humble and thorough in your responses significantly speeds up the approval process. If you're stuck on a specific CRAN error, it's often helpful to search the R-devel mailing list; chances are, someone else has struggled with the exact same obscure Windows-specific linking error you're seeing.

# Typical workflow for the final polish
devtools::document() 
devtools::check() # Ensure 0 errors, 0 warnings
# If everything is green:
devtools::submit_cran()



📋 Practical Task

Fixing the fluxR Submission Failures

You are pretending to be the maintainer of a package called fluxR. You just received an email from CRAN stating that your package was rejected for two specific reasons. Your goal is to modify the provided package files to satisfy the CRAN requirements.

The CRAN Email states:

  • Error: The DESCRIPTION file is missing the License field. All packages must have a valid license (e.g., MIT, GPL-3).
  • Error: The function compute_carbon_sink() is called in the examples of calculate_flux(), but compute_carbon_sink() is not exported in the NAMESPACE file.

Your Task:

  1. Update the DESCRIPTION file to include License: MIT.
  2. Modify the NAMESPACE file to export the compute_carbon_sink function using the export() command.
  3. Write a short "Response to Maintainer" note explaining that you have added the license and exported the missing function to ensure the examples run correctly.
Rating
0 0

There are no comments for now.

to be the first to leave a comment.