Specific Use Case - Setting up a "Standard" project with common libraries

94 views
Skip to first unread message

Peter Dunham

unread,
Mar 13, 2017, 10:59:53 AM3/13/17
to packrat-discuss
I have been using Packrat for several months and love it for managing and moving projects between machines.

I have a particular USE CASE question.  I am wondering if any other Packraters (PackRatees?)  have figured out how to do this.  It is possible it is very obvious and I am just missing it.


Use Case Description: 

As a developer, I want a bare-bones packrat project that has common installs that I would like to have already installed in any project I start.  For instance, I know I want dplyr installed for each project.  I am using RStudio. For instance, I create a standard project library in RStudio called "Basic Project".  I install "dplyr" in my "Basic Project".  I bundle it.  Now I want to start a new project to work on some analysis, say "Novel Data Analysis", I know I will need the dplyr library.  So I unbundle the my "Basic Project" project to a new name, an empty project which I name "Novel Data Analysis".  Now I am ready to start in my "Novel Data Analysis" project and I don't need to manually install "dplyr" from the console. 


Is there a way to get this desired functionality?


Issue I am running into:
  (1) Right now I am having to manually install "dplyr" into packrat for each new project.  This is because if I bundle and unbundle a project - the project is unbundled in a Project folder with the original project name.  I have not found a way to rename a Project in RStudio, or through Packrat. 


Kevin Ushey

unread,
Mar 13, 2017, 1:05:03 PM3/13/17
to Peter Dunham, packrat-discuss
Hi Peter,

This sort of workflow wasn't originally envisioned regarding the use of packrat bundles -- that is, rather than acting as templates for new projects, they just act as snapshots of a specific project at a point in time.

That said, the packrat lockfile (located at 'packrat/packrat.lock') _is_ portable, so in theory you could initialize new projects in this way:

   1. Create a new project,
   2. Copy the 'project default' packrat lockfile to that project's 'packrat/packrat.lock',
   3. Call 'packrat::restore()' to restore that project.

Although we don't have a simple workflow that encapsulates this at the moment, the next version of RStudio will come with support for package-provided project templates, and so Packrat could potentially define a function that could be used by RStudio to support a workflow such as this (inside or outside of RStudio).

Best,
Kevin

--
You received this message because you are subscribed to the Google Groups "packrat-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to packrat-discuss+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter Dunham

unread,
Mar 13, 2017, 5:20:42 PM3/13/17
to packrat-discuss
Thanks Kevin! Your reply makes senses and clears up if I was just missing how to do this. 

Peter Gensler

unread,
May 26, 2017, 11:42:33 PM5/26/17
to packrat-discuss
Peter,

One of the workarounds I have found for this is to use the pacman package, which has some very common functionality that I think it would be nice to incorporate into Packrat. Packrat is aimed at dependency issues (which is definitely necessary), not necessarily easily loading/unloading a package into an analysis. I find myself using this even to create basic reprex's, as I need to load given packages to ensure the reprex runs. 

Are features like this on the roadmap for packrat in the near future, or a new package that is aimed at easily loading packages for an analysis? I love using new packages for analysis work, but I wish packrat had these features more accessible/lightweight.

##View packages currently loaded:
#View what packages I currently have loaded in my workspace
print(.packages())
#Load pacman, and load all packages needed for this analysis
library(pacman)
pacman::p_load(ggplot2,dplyr,stringr,tidyjson, readr, R.utils, purrr, tidyr, janitor, textclean, tibble, XML,rvest, data.table, lubridate, ggthemes, magrittr, formattable,corrr)
#Check to ensure packages are loaded
p_loaded()

Let me know if this helps or not.
Reply all
Reply to author
Forward
0 new messages