-
Notifications
You must be signed in to change notification settings - Fork 2
/
packageInfo.R
55 lines (45 loc) · 1.48 KB
/
packageInfo.R
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
#!/usr/bin/R
usage <- function(){
usage.str = "\nUsage: Rscript packageInfo.R
\"pkgs='[vector packages for which to fetch info; REQUIRED]'\"
\"fields='[vector of information fields to fetch; DEFAULT is all fields returned by installed.packages():
c(\"Package\",\"LibPath\",\"Version\",
\"Priority\",\"Depends\",\"Imports\",
\"LinkingTo\",\"Suggests\",\"Enhances\",
\"License\",\"License_is_FOSS\",\"License_restricts_use\",
\"OS_type\",\"MD5sum\",\"NeedsCompilation\",
\"Built\")]'\"
\n
Example: Rscript packageInfo.R \"pkgs=c('gplots','scales')\" \"fields=c('Version','LibPath')\"
\n\n"
cat(usage.str)
}
## defaults
fields = c("Package","LibPath","Version",
"Priority","Depends","Imports",
"LinkingTo","Suggests","Enhances",
"License","License_is_FOSS","License_restricts_use",
"OS_type","MD5sum","NeedsCompilation",
"Built")
## get user input
args=(commandArgs(TRUE))
if(length(args)==0){
## print usage
usage()
q()
}
for(i in 1:length(args)){
eval(parse(text=args[i]))
}
if(!exists("pkgs")){
usage()
q()
}
ip <- as.data.frame(installed.packages())
psearch <- paste(pkgs,collapse="|")
fsearch <- paste(fields,collapse="|")
cat("\n")
res <- as.data.frame(ip[grep(psearch,rownames(ip),ignore.case=TRUE),grep(fsearch,names(ip),ignore.case=TRUE)])
names(res) <- names(ip)[grep(fsearch,names(ip),ignore.case=TRUE)]
res
cat("\n")