I have a lot of R
packages installed from CRAN
as well as GitHub
, and I was wondering how I could extract only those packages installed from CRAN, or only those from GitHub?
installed.packages()
does not list any variables that I could use, as far as I understand...
packages <- installed.packages()[,1]
packages.keep <- sapply(packages, function(x) {
url <- packageDescription(x)$URL
if (length(grep("github", x = url)) == 0) {
return(FALSE)
}
else {
return(TRUE)
}
})
packages[packages.keep]
> packages[packages.keep]
curl data.table DBI devtools dplyr
"curl" "data.table" "DBI" "devtools" "dplyr"
evaluate forecast ggplot2 git2r gridExtra
"evaluate" "forecast" "ggplot2" "git2r" "gridExtra"
Hmisc httr mailR memoise mime
"Hmisc" "httr" "mailR" "memoise" "mime"
plyr R.oo R.utils R6 Rcpp
"plyr" "R.oo" "R.utils" "R6" "Rcpp"
RcppArmadillo reshape2 roxygen2 RSQLite rversions
"RcppArmadillo" "reshape2" "roxygen2" "RSQLite" "rversions"
scales whisker
"scales" "whisker"
To verify this result, here is the URL information for the ggplot2
package:
URL: http://ggplot2.org, https://github.com/hadley/ggplot2
It is clear that this package in part originated from GitHub, and it should appear in the list. If you want to work with packages which did not come from GitHub, you can easily modify my code.