How to find out which package was installed from GitHub in my R library?

Related searches

I want to know how many packages in my current library were installed from GitHub but can't find a way to go about it

# The number of installed packages in my library
length(.packages(all.available=TRUE))
[1] 145

This R-bloggers post showed the versions of the packages but not where they were installed from https://www.r-bloggers.com/list-of-user-installed-r-packages-and-their-versions/

ip <- as.data.frame(installed.packages()[, c(1, 3:4)])
rownames(ip) <- NULL
ip <- ip[is.na(ip$Priority), 1:2, drop=FALSE]
print(ip, row.names=FALSE)

              Package     Version
                abind       1.4-5
              acepack       1.4.1
                 ade4      1.7-10
            albersusa       0.3.0
        AnnotationDbi      1.40.0
          ansistrings       1.0.0
                  ape         5.0
                  aqp        1.15
                  ash      1.0-15
           assertthat       0.2.0
                astsa         1.8
                ATmet         1.2
              automap      1.0-14
            backports       1.1.2
               base64         2.0
            base64enc       0.1-3
                bazar       1.0.6
               BBmisc        1.11
             beeswarm       0.2.3
                   BH    1.66.0-1

I thought I could load all the packages then run devtools::session_info() to find what I want https://www.r-bloggers.com/loading-all-installed-r-packages/

lapply(.packages(all.available=TRUE), 
        function(x) library(x, character.only=TRUE))

But then I ran into another problem: loading too many packages at the same time maximal number of DLLs reached.... Package changepoint is only the 53th package out of 100+ packages

 Error: package or namespace load failed for ‘changepoint’ in inDL(x, as.logical(local), as.logical(now), ...):
 unable to load shared object 'C:/RCat/library/changepoint/libs/x64/changepoint.dll':
  `maximal number of DLLs reached... 

Edit 1: I used the code suggested by @Dason but had these errors

# empty folder
> sapply(dir(.libPaths()), isGithub)
Error: $ operator is invalid for atomic vectors
In addition: Warning message:
In packageDescription(pkg) :
  DESCRIPTION file of package 'file31043e741b3f' is missing or broken

# only lattice.dll left in lattice/lib/x64  
> sapply(dir(.libPaths()), isGithub)
Error: $ operator is invalid for atomic vectors
In addition: Warning message:
In packageDescription(pkg) :
  DESCRIPTION file of package 'lattice' is missing or broken

Many thanks for any help!!!

Use the source. If you examine the code for devtools::session_info() the relevant info seems to be in devtools::package_info(). The code for package_info is:

> getAnywhere("package_info")
A single object matching ‘package_info’ was found
It was found in the following places
  namespace:devtools
with value

function (pkgs = loadedNamespaces(), include_base = FALSE, libpath = NULL) 
{
    desc <- suppressWarnings(lapply(pkgs, packageDescription, 
        lib.loc = libpath))
    not_installed <- vapply(desc, identical, logical(1), NA)
    if (any(not_installed)) {
        stop("`pkgs` ", paste0("'", pkgs[not_installed], "'", 
            collapse = ", "), " are not installed", call. = FALSE)
    }
    if (!include_base) {
        base <- vapply(pkgs, pkg_is_base, logical(1))
        pkgs <- pkgs[!base]
    }
    pkgs <- sort_ci(pkgs)
    attached <- pkgs %in% sub("^package:", "", search())
    desc <- lapply(pkgs, packageDescription, lib.loc = libpath)
    version <- vapply(desc, function(x) x$Version, character(1))
    date <- vapply(desc, pkg_date, character(1))
    source <- vapply(desc, pkg_source, character(1))
    pkgs_df <- data.frame(package = pkgs, `*` = ifelse(attached, 
        "*", ""), version = version, date = date, source = source, 
        stringsAsFactors = FALSE, check.names = FALSE)
    rownames(pkgs_df) <- NULL
    class(pkgs_df) <- c("packages_info", "data.frame")
    pkgs_df
}
<bytecode: 0x000000000e211f50>
<environment: namespace:devtools>

Basically the output from utils::packageDescription() is getting passed to devtools::pkg_source(). So if you want you could just check what the output of packageDescription looks like and write a function to identify if the description flags it as a github package or not. I made a first pass at it although I haven't tested extensively.

isGithub <- function(pkg){!is.null(packageDescription(pkg)$GithubRepo)}

And then to run it on all of our packages we can just list the folders in .libPaths as such

sapply(dir(.libPaths()), isGithub)

Checking a package � R packages, An important part of the package development process is R CMD check . R CMD It's essential if you're planning on submitting to CRAN, but it's useful even if you 're not because it If you use GitHub, you'll learn precisely how to do that with Travis-CI. You must check a source package, not a binary or installed package. Here’s some code that provides an easy way to check whether specific packages are in the default Library. If they are, they’re simply loaded via library(). If any packages are missing, they’re installed (with dependencies) into the default Library and are then loaded. (This is a re-post of an entry that appeared on my old blog - see here).

A little modification that allows you to go through your libraries and determine the source of each including the name of the github repo

library(tidyverse)
#> Registered S3 methods overwritten by 'ggplot2':
#>   method         from 
#>   [.quosures     rlang
#>   c.quosures     rlang
#>   print.quosures rlang
#> Registered S3 method overwritten by 'rvest':
#>   method            from
#>   read_xml.response xml2
allmypackages <- as.data.frame(installed.packages())
allmypackages <- allmypackages %>%
  filter(Priority != "base" | is.na(Priority)) %>%
  select(-c(Enhances:MD5sum, LinkingTo:Suggests)) %>%
  droplevels()

package_source <- function(pkg){
  x <- as.character(packageDescription(pkg)$Repository)
  if (length(x)==0) {
    y <- as.character(packageDescription(pkg)$GithubRepo)
    z <- as.character(packageDescription(pkg)$GithubUsername)
    if (length(y)==0) {
      return("Other")
    } else {
      return(str_c("GitHub repo = ", z, "/", y))
    }
  } else {
    return(x)
  }
}

head(sapply(allmypackages$Package, package_source),60)
#>  [1] "CRAN"                            "CRAN"                           
#>  [3] "CRAN"                            "CRAN"                           
#>  [5] "CRAN"                            "CRAN"                           
#>  [7] "CRAN"                            "CRAN"                           
#>  [9] "CRAN"                            "CRAN"                           
#> [11] "CRAN"                            "CRAN"                           
#> [13] "CRAN"                            "CRAN"                           
#> [15] "CRAN"                            "CRAN"                           
#> [17] "CRAN"                            "CRAN"                           
#> [19] "CRAN"                            "CRAN"                           
#> [21] "CRAN"                            "CRAN"                           
#> [23] "CRAN"                            "CRAN"                           
#> [25] "CRAN"                            "CRAN"                           
#> [27] "CRAN"                            "CRAN"                           
#> [29] "CRAN"                            "CRAN"                           
#> [31] "CRAN"                            "CRAN"                           
#> [33] "CRAN"                            "CRAN"                           
#> [35] "CRAN"                            "CRAN"                           
#> [37] "CRAN"                            "CRAN"                           
#> [39] "CRAN"                            "CRAN"                           
#> [41] "CRAN"                            "CRAN"                           
#> [43] "CRAN"                            "CRAN"                           
#> [45] "Other"                           "R-Forge"                        
#> [47] "CRAN"                            "CRAN"                           
#> [49] "CRAN"                            "CRAN"                           
#> [51] "CRAN"                            "CRAN"                           
#> [53] "CRAN"                            "CRAN"                           
#> [55] "CRAN"                            "CRAN"                           
#> [57] "CRAN"                            "CRAN"                           
#> [59] "GitHub repo = cjtexas/colourgen" "CRAN"
allmypackages$whereat <- sapply(allmypackages$Package, package_source)

Created on 2019-05-14 by the reprex package (v0.2.1)

r-lib/available: Check if a package name is available to use, Can suggest possible names based on text in the package title or description. Installation. You can install available from CRAN with: install.packages("available "). I am in the process of figuring out how to use my university cluster. It has 2 versions of R installed. System-wide R 2.11 (Debian 6.0) and R 2.14.2 in a non-standard location.

Thanks to @Dason, I finally got this to work

Function to find packages installed from GitHub

isGithub <- function(pkg){
    !is.null(packageDescription(pkg)$GithubRepo)
}

Get all packages in my local library

my_lib <- as.data.frame(library()$result, stringsAsFactors=FALSE)

Check which packages are from GitHub

result <- sapply(my_lib$Package, isGithub)
df <- data.frame(package = names(result), github_or_not = result, 
             stringsAsFactors = FALSE)
head(df[df$result == TRUE, ])

     names.result. result
4           bindr   TRUE
5        bindrcpp   TRUE
6        blogdown   TRUE
9          chroma   TRUE
17          dplyr   TRUE
21          editR   TRUE

Installing R Packages from GitHub, In this example, we are installing the flipPlots package created by Displayr. 1. 2. library (devtools). install_github (� package found along lib.locand returns a matrix of package names, library paths and version numbers. The information found is cached (by library) for the Rsession and specified fieldsargument, and updated only if the top-level

R Packages: A Beginner's Guide, Where can you find packages? The installation and usage: how can you install packages from CRAN, CRAN mirrors, Bioconductor or Github? Let’s try that by running the following commands in the R console: myPaths <- .libPaths() # get the paths myPaths <- c(myPaths[2], myPaths[1]) # switch them .libPaths(myPaths) # reassign them. Now view the results using the Tools -> Install Packages… menu: Now the common library is the default.

A Helpful Way to Install R Packages Hosted on GitHub, Suggest Repositories. gh_install_packages() prompts you to install the suggested packages. But you may just want to know what will be� - The older package version needed may not be compatible with the version of R you have installed. In this case, you will either need to downgrade R to a compatible version or update your R code to work with a newer version of the package.

npm list -g is the same, but for globally installed packages. To get only your top-level packages (basically, the ones you told npm to install and you listed in the package.json), run npm list --depth=0: ❯ npm list --depth=0 /Users/flavio/dev/node/cowsay └── cowsay@1.3.1

Comments
  • You can use packageDescription("package-name")$Repository to get this information without having to load the package - so perhaps use this as the function in your lapply.
  • Thank you so much!!! I had errors using your code. Would you mind checking the updates in my question?
  • @IloveCatRPython instead of dir(.libPaths()) use a clean vector of package names that you want to check. That was my quick and dirty way to get that but you can clean it up a bit. installed.packages() is probably a better way to do that part.
  • Thank you again! That is very helpful suggestion. I post an answer that works for me
  • Would like to test this solution. What is df here? Can you update to make it fully reproducible?