1
- # ' Find all dependencies of a CRAN or dev package.
2
- # '
3
- # ' Find all the dependencies of a package and determine whether they are ahead
4
- # ' or behind CRAN. A \code{print()} method identifies mismatches (if any)
5
- # ' between local and CRAN versions of each dependent package; an
6
- # ' \code{update()} method installs outdated or missing packages from CRAN.
7
- # '
8
- # ' @param pkg A character vector of package names. If missing, defaults to
9
- # ' the name of the package in the current directory.
10
- # ' @param dependencies Which dependencies do you want to check?
11
- # ' Can be a character vector (selecting from "Depends", "Imports",
12
- # ' "LinkingTo", "Suggests", or "Enhances"), or a logical vector.
13
- # '
14
- # ' \code{TRUE} is shorthand for "Depends", "Imports", "LinkingTo" and
15
- # ' "Suggests". \code{NA} is shorthand for "Depends", "Imports" and "LinkingTo"
16
- # ' and is the default. \code{FALSE} is shorthand for no dependencies (i.e.
17
- # ' just check this package, not its dependencies).
18
- # ' @param quiet If \code{TRUE}, suppress output.
19
- # ' @param upgrade If \code{TRUE}, also upgrade any of out date dependencies.
20
- # ' @param repos A character vector giving repositories to use.
21
- # ' @param type Type of package to \code{update}. If "both", will switch
22
- # ' automatically to "binary" to avoid interactive prompts during package
23
- # ' installation.
24
- # '
25
- # ' @param object A \code{package_deps} object.
26
- # ' @param ... Additional arguments passed to \code{\link{install.packages}}.
27
- # '
28
- # ' @return
29
- # '
30
- # ' A \code{data.frame} with columns:
31
- # '
32
- # ' \tabular{ll}{
33
- # ' \code{package} \tab The dependent package's name,\cr
34
- # ' \code{installed} \tab The currently installed version,\cr
35
- # ' \code{available} \tab The version available on CRAN,\cr
36
- # ' \code{diff} \tab An integer denoting whether the locally installed version
37
- # ' of the package is newer (1), the same (0) or older (-1) than the version
38
- # ' currently available on CRAN.\cr
39
- # ' }
40
- # '
41
- # ' @export
42
- # ' @examples
43
- # ' \dontrun{
44
- # ' package_deps("devtools")
45
- # ' # Use update to update any out-of-date dependencies
46
- # ' update(package_deps("devtools"))
47
- # ' }
48
- package_deps <- function (pkg , dependencies = NA , repos = getOption(" repos" ),
1
+
2
+ package_deps <- function (packages , dependencies = NA ,
3
+ repos = getOption(" repos" ),
49
4
type = getOption(" pkgType" )) {
5
+
50
6
if (identical(type , " both" )) {
51
7
type <- " binary"
52
8
}
@@ -57,7 +13,7 @@ package_deps <- function(pkg, dependencies = NA, repos = getOption("repos"),
57
13
repos [repos == " @CRAN@" ] <- " http://cran.rstudio.com"
58
14
cran <- available_packages(repos , type )
59
15
60
- deps <- sort(find_deps(pkg , cran , top_dep = dependencies ))
16
+ deps <- sort(find_deps(packages , cran , top_dep = dependencies ))
61
17
62
18
# Remove base packages
63
19
inst <- installed.packages()
@@ -82,12 +38,12 @@ package_deps <- function(pkg, dependencies = NA, repos = getOption("repos"),
82
38
)
83
39
}
84
40
85
- # ' @export
86
- # ' @rdname package_deps
87
- dev_package_deps <- function (pkg = " ." , dependencies = NA ,
41
+ dev_package_deps <- function (pkgdir , dependencies = NA ,
88
42
repos = getOption(" repos" ),
89
43
type = getOption(" pkgType" )) {
90
- install_dev_remotes(pkg )
44
+
45
+ pkg <- load_pkg_description(pkgdir )
46
+ install_dev_remotes(pkgdir )
91
47
92
48
dependencies <- tolower(standardise_dep(dependencies ))
93
49
dependencies <- intersect(dependencies , names(pkg ))
@@ -181,36 +137,6 @@ has_dev_remotes <- function(pkg) {
181
137
}
182
138
183
139
184
- # ' @export
185
- print.package_deps <- function (x , show_ok = FALSE , ... ) {
186
- class(x ) <- " data.frame"
187
-
188
- ahead <- x $ diff > 0L
189
- behind <- x $ diff < 0L
190
- same_ver <- x $ diff == 0L
191
-
192
- x $ diff <- NULL
193
- x [] <- lapply(x , format )
194
-
195
- if (any(behind )) {
196
- cat(" Needs update -----------------------------\n " )
197
- print(x [behind , , drop = FALSE ], row.names = FALSE , right = FALSE )
198
- }
199
-
200
- if (any(ahead )) {
201
- cat(" Not on CRAN ----------------------------\n " )
202
- print(x [ahead , , drop = FALSE ], row.names = FALSE , right = FALSE )
203
- }
204
-
205
- if (show_ok && any(same_ver )) {
206
- cat(" OK ---------------------------------------\n " )
207
- print(x [same_ver , , drop = FALSE ], row.names = FALSE , right = FALSE )
208
- }
209
- }
210
-
211
- # ' @export
212
- # ' @rdname package_deps
213
- # ' @importFrom stats update
214
140
update.package_deps <- function (object , ... , quiet = FALSE , upgrade = TRUE ) {
215
141
ahead <- object $ package [object $ diff == 2L ]
216
142
if (length(ahead ) > 0 && ! quiet ) {
@@ -236,29 +162,29 @@ update.package_deps <- function(object, ..., quiet = FALSE, upgrade = TRUE) {
236
162
237
163
}
238
164
239
- install_packages <- function (pkgs , repos = getOption(" repos" ),
165
+ install_packages <- function (packages , repos = getOption(" repos" ),
240
166
type = getOption(" pkgType" ), ... ,
241
167
dependencies = FALSE , quiet = NULL ) {
242
168
if (identical(type , " both" ))
243
169
type <- " binary"
244
170
if (is.null(quiet ))
245
171
quiet <- ! identical(type , " source" )
246
172
247
- message(" Installing " , length(pkgs ), " packages: " ,
248
- paste(pkgs , collapse = " , " ))
249
- utils :: install.packages(pkgs , repos = repos , type = type , ... ,
173
+ message(" Installing " , length(packages ), " packages: " ,
174
+ paste(packages , collapse = " , " ))
175
+ utils :: install.packages(packages , repos = repos , type = type , ... ,
250
176
dependencies = dependencies , quiet = quiet )
251
177
}
252
178
253
- find_deps <- function (pkgs , available = available.packages(), top_dep = TRUE ,
254
- rec_dep = NA , include_pkgs = TRUE ) {
255
- if (length(pkgs ) == 0 || identical(top_dep , FALSE ))
179
+ find_deps <- function (packages , available = available.packages(),
180
+ top_dep = TRUE , rec_dep = NA , include_pkgs = TRUE ) {
181
+ if (length(packages ) == 0 || identical(top_dep , FALSE ))
256
182
return (character ())
257
183
258
184
top_dep <- standardise_dep(top_dep )
259
185
rec_dep <- standardise_dep(rec_dep )
260
186
261
- top <- tools :: package_dependencies(pkgs , db = available , which = top_dep )
187
+ top <- tools :: package_dependencies(packages , db = available , which = top_dep )
262
188
top_flat <- unlist(top , use.names = FALSE )
263
189
264
190
if (length(rec_dep ) != 0 && length(top_flat ) > 0 ) {
@@ -269,7 +195,7 @@ find_deps <- function(pkgs, available = available.packages(), top_dep = TRUE,
269
195
rec_flat <- character ()
270
196
}
271
197
272
- unique(c(if (include_pkgs ) pkgs , top_flat , rec_flat ))
198
+ unique(c(if (include_pkgs ) packages , top_flat , rec_flat ))
273
199
}
274
200
275
201
@@ -287,24 +213,9 @@ standardise_dep <- function(x) {
287
213
}
288
214
}
289
215
290
- # ' Update packages that are missing or out-of-date.
291
- # '
292
- # ' Works similarly to \code{install.packages()} but doesn't install packages
293
- # ' that are already installed, and also upgrades out dated dependencies.
294
- # '
295
- # ' @param pkgs Character vector of packages to update.
296
- # ' @inheritParams package_deps
297
- # ' @seealso \code{\link{package_deps}} to see which packages are out of date/
298
- # ' missing.
299
- # ' @export
300
- # ' @examples
301
- # ' \dontrun{
302
- # ' update_packages("ggplot2")
303
- # ' update_packages(c("plyr", "ggplot2"))
304
- # ' }
305
- update_packages <- function (pkgs , dependencies = NA ,
216
+ update_packages <- function (packages , dependencies = NA ,
306
217
repos = getOption(" repos" ),
307
218
type = getOption(" pkgType" )) {
308
- pkgs <- package_deps(pkgs , repos = repos , type = type )
309
- update(pkgs )
219
+ packages <- package_deps(packages , repos = repos , type = type )
220
+ update(packages )
310
221
}
0 commit comments