Skip to content

Commit

Permalink
Make igraph a suggested package (change dependency from Imports to Su…
Browse files Browse the repository at this point in the history
…ggests). Closes #52
  • Loading branch information
andrie committed Jan 15, 2015
1 parent 0215f62 commit a63d23f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 15 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ Imports:
tools,
XML,
httr,
igraph,
methods
Suggests:
testthat(>= 0.9),
knitr
knitr,
igraph
VignetteBuilder: knitr
1 change: 0 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export(pkgDep)
export(updatePackages)
export(updateRepoIndex)
import(XML)
import(igraph)
importFrom(httr,GET)
importFrom(httr,content)
importFrom(httr,stop_for_status)
Expand Down
6 changes: 4 additions & 2 deletions R/makeDepGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ addDepType <- function(p, type = c("Imports", "Depends", "LinkingTo", "Suggests"
}


igraphNotAvailableMessage <- "makeDepGraph requires igraph. Install igraph and try again."

#' Create dependency graph from available packages.
#'
#' Each package is a node, and a dependency is an edge
#'
#' @inheritParams pkgDep
#' @inheritParams makeRepo
#'
#' @import igraph
#' @export
#' @family dependency functions
#'
Expand All @@ -45,7 +46,8 @@ makeDepGraph <- function(
suggests=TRUE, enhances=FALSE,
includeBasePkgs=FALSE, ...)
{

if(!requireNamespace("igraph")){stop(igraphNotAvailableMessage)}

if(missing(availPkgs)) {
availPkgs <- pkgAvail(repos=repos, type=type)
}
Expand Down
3 changes: 1 addition & 2 deletions R/plot.pkgDepGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#' @param ... Ignored
#' @export
#'
#' @import igraph
#'
#' @family dependency functions
#'
#' @example /inst/examples/example_plot.pkgDepGraph.R
Expand All @@ -25,6 +23,7 @@ plot.pkgDepGraph <- function(
cex=1,
...)
{
if(!requireNamespace("igraph")){stop(igraphNotAvailableMessage)}
class(x) <- "igraph"
plotColours <- c("grey80", "orange")
if(missing("pkgsToHighlight")) {
Expand Down
59 changes: 51 additions & 8 deletions tests/testthat/test-2-makeDepGraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ checkPkgDepFunctions <- function(pkg, availPkgs = cranJuly2014,
enhances=FALSE,
includeBasePkgs=FALSE){

require(igraph)
require(igraph, quietly = TRUE)
p1 <- pkgDep(pkg, availPkgs=availPkgs,
repos=repos, type=type,
suggests=suggests, enhances=enhances,
Expand All @@ -31,6 +31,49 @@ checkPkgDepFunctions <- function(pkg, availPkgs = cranJuly2014,

context("makeDepGraph ")

mock_require <- function(pkg, ...){
packages.to.exclude <- c("igraph")
inSearchPath <- any(
grepl(sprintf("package:%s$", paste(packages.to.exclude, collapse = "|")), search())
)
if(inSearchPath) stop("Required package already in search path")

package <- as.character(substitute(pkg))
if(package %in% packages.to.exclude)
FALSE
else
base::requireNamespace(package, character.only = TRUE, ...)
}


test_that("throws error if igraph not available", {
with_mock(
`base::requireNamespace` = function(pkg, ...){
packages.to.exclude <- c("igraph")
inSearchPath <- any(
grepl(sprintf("package:%s$", paste(packages.to.exclude, collapse = "|")), search())
)
if(inSearchPath) stop("Required package already in search path")

package <- as.character(substitute(pkg))
if(package %in% packages.to.exclude)
FALSE
else
base::requireNamespace(package, character.only = TRUE, ...)
},
{
expect_false(requireNamespace("igraph"))

tag <- "MASS"

expect_error(
makeDepGraph(tag, availPkgs=cranJuly2014)
)

})

})

test_that("makeDepGraph and pgkDep gives similar results for MASS", {


Expand All @@ -39,7 +82,7 @@ test_that("makeDepGraph and pgkDep gives similar results for MASS", {
expect_true(
checkPkgDepFunctions(tag)
)

skip_on_cran()

expect_true(
Expand Down Expand Up @@ -81,9 +124,9 @@ test_that("makeDepGraph and pgkDep gives similar results for chron", {
test_that("makeDepGraph and pgkDep gives similar results for data.table", {

skip_on_cran()

tag <- "data.table"

expect_true(
checkPkgDepFunctions(tag)
)
Expand All @@ -102,9 +145,9 @@ test_that("makeDepGraph and pgkDep gives similar results for data.table", {
test_that("makeDepGraph and pgkDep gives similar results for ggplot2", {

skip_on_cran()

tag <- "ggplot2"

expect_true(
checkPkgDepFunctions(tag)
)
Expand All @@ -124,9 +167,9 @@ test_that("makeDepGraph and pgkDep gives similar results for ggplot2", {
test_that("makeDepGraph and pgkDep gives similar results for complex query", {

skip_on_cran()

tag <- c("ggplot2", "data.table", "plyr", "knitr", "shiny", "xts", "lattice")

expect_true(
checkPkgDepFunctions(tag)
)
Expand Down

0 comments on commit a63d23f

Please sign in to comment.