可以单独提取从CRAN和Github安装的R包吗?

时间:2015-09-09 09:27:04

标签: r cran

我从R以及CRAN安装了很多GitHub个软件包,我想知道如何只提取从CRAN安装的软件包,或者只提取来自GitHub的软件包?

根据我的理解,

installed.packages()没有列出我可以使用的任何变量......

2 个答案:

答案 0 :(得分:1)

我会尝试类似的事情:

local <- as.character(installed.packages()[,1])
mirror <- as.character(available.packages()[,1])
local[!(local %in% mirror)]

更多细化:

local <- installed.packages()[,c(1,3)]
mirror <- available.packages()[,c(1,2)]
dif.install <- local[!(local[,1] %in% mirror[,1]),]
same.install <- local[(local[,1] %in% mirror[,1]),]
dif.version <- same.install[!(same.install[,2] %in% mirror[,2]),]
out <- merge(dif.version, mirror[(mirror[,1] %in% dif.version[,1]),], by = "Package")
colnames(out) <- c("Package", "Other", "CRAN")
out

给我安装:

     Package     Other  CRAN
1 data.table     1.9.5 1.9.4
2 manipulate 0.98.1103 1.0.1
3      Zelig     5.0-5 4.2-1

答案 1 :(得分:1)

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"

要验证此结果,请参阅以下ggplot2包的网址信息:

URL: http://ggplot2.org, https://github.com/hadley/ggplot2

很明显,这个包部分来自GitHub,它应该出现在列表中。如果您想使用来自GitHub的 not 的软件包,您可以轻松修改我的代码。