R package size and packrat

I am developing an R package using packrat. Unfortunately, the packrat folder has become very large (327 MB), so that my compressed package file exceeds CRAN's 100 MB threshold value for new packages. Is there a way to effectively reduce the packrat folder size? Thanks!
Cheers, Christian

Hi @cseiler! Welcome!

Can you explain a bit more about what you're doing, and why you wound up using packrat?

packrat is commonly used to reproduce the set of R packages necessary for running the code for a project (e.g., a specific data analysis). It does this by creating a local package library inside the project folder. A package that you hope to submit to CRAN shouldn't be carrying around copies of all the packages it depends on — CRAN packages have their own system for specifying dependencies (see: http://r-pkgs.had.co.nz/description.html#dependencies).

So I'm not sure you should be using packrat at all in this case, but perhaps I haven't understood your situation completely?

1 Like

Hi @jcblum - thank you very much for your prompt reply. I think I have a misconception of how to use packrat then. Let's say I want to create a new package using rstudio. I start a new project, select rpackage as project type, and check the packrat tick box. rstudio then creates the files and folders:

  • DESCRIPTION
  • man
  • myNewProject.Rproj
  • NAMESPACE
  • packrat
  • R

So the packrat folder is located in the directory that contains files and folders relevant to my new package. Now, you mentioned that the packrat folder should not be part of my new package, may I just move it elsewhere then? Thank you very much for your help. You can tell this is my first package. :grinning:
Cheers, Christian

Hi, @jcblum is correct when she mentioned the main use-case for something like packrat - reproducible runs for your projects. If your plan is to eventually publish your package to CRAN, you should not use packrat since it doesn't really have any use in this use-case. As for what you should do instead, I would recommend going over the "R packages" book that explains the workflow for how you would normally develop CRAN-bound package:

As for why you would want to use packrat with the package, is that it's often a good idea to package your analysis into a package since it gives you a lot of nice things. In this case, packrat will guarantee that your analysis can be re-run by anyone and results will be the same all the time.

1 Like

Hi @mishabalyasin - I now see that when I build the source package, the packrat folder is no longer included, which solves my problem. Thanks to both!
Cheers, Christian

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.