library(pkgsearch) query = 'infectious disease modelling' packages = pkg_search(query) # extract data from the search top_packages = as.data.frame(packages) name = top_packages$package description = top_packages$title url = gsub('[[:space:]]', '', top_packages$url) url_list = strsplit(url, ',') # utility git_or_no = function(url_list, git) { # FIXME: check for multiple githubs or multiple homepages out_list = lapply(url_list, grep, pattern = 'https://github.com/', value = TRUE, invert = !git) mode(out_list) = 'character' ifelse(out_list == "character(0)", NA, out_list) } # find packages with github urls github = git_or_no(url_list, git = TRUE) # infer package homepage # (if provided url is not a github repo, assume that it is a package homepage) home = git_or_no(url_list, git = FALSE) # make cran urls cran_pkg_url = 'https://cran.r-project.org/web/packages/' cran = paste0(cran_pkg_url, name, '/index.html') top_packages = data.frame( name = name, description = description, home = home, cran = cran, github = github )