-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPackrat.Rpres
177 lines (102 loc) · 5.11 KB
/
Packrat.Rpres
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
Fun With Packrat!!
========================================================
author: Mitch Walters and Travis Guy
date: 4-10-15
*********
![Packrat](http://www.yeswecoupon.com/wp-content/Images/2013/05/pack-rat.gif)
What is a library?
=============================
![library](https://yearlongphotos.files.wordpress.com/2012/11/october-17-2012-boise-library.jpg?w=1254&h=836)
-----------
library = directory where packages are stored
Packrat makes a private library for you and helps you to keep it clean and organized
to see what's in your library
> library()
========================================================
## Why Use Packrat?
![Packrat](http://photos.happyherbivore.com/2013/08/packrat111208.gif)
-------------
- Isolation
- Portability
- Reproducibility
===========================================================
## Why Use Packrat?
- Have you ever had to use trial-and-error to figure out what R packages you need to install to make someone else’s code work and then been left with those packages globally installed forever???
- Have you ever updated a package to get code in one of your projects to work, only to find that the updated package makes code in another project stop working???
========================================================
## How it works
- Packrat stores your package dependencies inside your project directory
rather than in your personal R library
- This directory is known as your **private library**
- When you start an R session in a packrat project directory, R will only
look for packages in your private library
- if you install or remove a package, those changes are only made to your
private library
========================================================
## How it works
### **Restoring:** the process of installing packages to private libraries from a snapshot
- Private libraries don't usually travel well since the contents are compiled for your specific computer, OS, and R version
- Packrat takes a **snapshot** of your private library, which it saves to your project directory
- From this, Packrat can re-create the same private library on another computer
Installing Packrat
========================================================
![packrat](http://www.newswise.com/images/uploads/2009/04/03/fullsize/woodrat2juniper.jpg)
*********
> install.packages("packrat")
Set-up
========================================================
set up the project directory to use Packrat
> packrat::init:
- do this first thing before typing any other code
- include a path after init if you are not in your working directory
+ ex. packrat::init("~/projects/pollinatordata")
=============
If you have R-studio (v. 0.98.945 or newer), you can simply check the box!
![install packrat](http://rstudio.github.io/packrat/images/rstudio-newproject.png)
========================================================
## Congratulations! You have achieved isolation
![Isolation](http://www.picturesof.net/_images_300/Man_Relaxing_Alone_On_a_Small_Island_Royalty_Free_Clipart_Picture_090304-183107-378042.jpg)
-----------
- You’re no longer in an ordinary R project; you’re in a Packrat project.
- You now have your own private package library
- Any packages you install from inside a packrat project are only available to that project
- Any packages you install outside of the project are not available to the project
Installing Packages in your Private Library
========================================================
![Library](https://scontent-ord.xx.fbcdn.net/hphotos-xaf1/t31.0-8/338627_542099253028_2087102262_o.jpg)
*****
> install.packages("reshape2")
> install.packages("stringr")
> install.packages("ggplot2")
- install a package the way you normally would
Taking a Snapshot of your Private Library
========================================================
![snapshot](http://pbskids.org/curiousgeorge/games/img/g_icon_snapshot_ovr.gif)
> packrat::snapshot()
Restoring Snapshots
========================================================
### If you want to run your project on a different computer
- After copying a project to a new computer, simply launch R from your project directory
- Packrat automates the whole process
- All of the packages in the snapshot will be installed in your project’s private package library.
Check Status
========================================================
To see if someone has deleted a package
> packrat::status()
Restoring Snapshots
========================================================
If you delete a package that you realize later you need or if a collaborator makes a change to a snapshot
> packrat::restore()
Cleaning Up
========================================================
- Packrat analyzes your code to determine if there are packages that were maybe needed at one time but are no
longer used
- You can then tell Packrat to remove these functions
- check the status
> packrat::status()
- Packrat will tell you which packages are installed but not needed
- Remove these unneeded packages
> packrat::clean()
Demonstration
========================================================
Now we will go through a brief interactive demonstration with Packrat