Skip to content

Commit

Permalink
Merge pull request #2 from inSilecoInc/testmore
Browse files Browse the repository at this point in the history
basic metanetwork() testing
  • Loading branch information
david-beauchesne authored Nov 23, 2023
2 parents ce4dcee + d6e265b commit 498a78d
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ jobs:
needs: check

- uses: r-lib/actions/check-r-package@v2
with:
error-on: '"error"'

- name: Code coverage
if: matrix.config.os == 'ubuntu-22.04'
Expand Down
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: metanetwork
Title: Circular Hierarchical Edge Bundling Graphs
Version: 0.0.0.9004
Version: 0.0.0.9005
Authors@R: c(
person(given = "David",
family = "Beauchesne",
Expand Down
29 changes: 16 additions & 13 deletions R/metanetwork.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
#' @param colLink color of links, if not provided in `links`. Can be a single numeric value or a numeric vector of length = `nrow(links)`.
#' @param linkWidth numeric, width of links, if not provided in `links`. Can be a single numeric value or a numeric vector of length = `nrow(links)`.
#' @param textSize numeric, size of text displayed on figure. All text displayed is a proportion of this parameter.
#' @param rad1 lower boundary for placement of individual network titles
#' @param rad2 upper boundary for placement of individual network titles
#' @param focus character, name of network(s) to focus on; if length(focus) == 1, all links towards a single network; if length(focus) > 1, links focused on identified networks
#' @param shadowNode logical, add a shadow around nodes
#' @param shadowLink color of links that are not focused on
#' @param export logical, export figure as png image
#' @param res resolution of png image
#' @param img_size height and width of png image
#' @param legend logical, add a legend to png image
#' @param rad1,rad2 lower and upper boundary for placement of individual network titles.
#' @param focus character, name of network(s) to focus on; if length(focus) == 1, all links towards a single network; if length(focus) > 1, links focused on identified networks.
#' @param shadowNode logical, add a shadow around nodes.
#' @param shadowLink color of links that are not focused on.
#' @param export logical, export figure as png image.
#' @param filename filename of the (ignored if `export` is FALSE).
#' @param res resolution of png image.
#' @param img_size height and width of png image.
#' @param legend logical, add a legend to png image.
#'
#' @examples
#' # Data 1
Expand All @@ -41,12 +41,13 @@ metanetwork <- function(
colLink = "#876b40",
linkWidth = 1,
textSize = 1,
rad1 = .925,
rad1 = 0.925,
rad2 = 1,
focus = NULL,
shadowNode = TRUE,
shadowLink = "#f4f4f4",
export = TRUE,
filename = "metanetwork.png",
res = 300,
img_size = 200,
legend = TRUE) {
Expand All @@ -69,7 +70,7 @@ metanetwork <- function(

# Check if data has the proper columns
chk <- all(c("network", "subnetwork", "category") %in% colnames(nodes))
if (!chk) stop("Columns `network`, `subnetwork` and `category` must be present in the data")
if (!chk) stop("Columns `network`, `subnetwork` and `category` must be present in `nodes`.")

# Check if colors are included in the data
chk <- "col" %in% colnames(nodes)
Expand Down Expand Up @@ -101,7 +102,7 @@ metanetwork <- function(

# Check if data has the proper columns
chk <- all(c("from", "to") %in% colnames(links))
if (!chk) stop("Columns `from` and `to` must be present in the data")
if (!chk) stop("Columns `from` and `to` must be present in `links`.")

# Check if colors are included in the data
chk <- "col" %in% colnames(links)
Expand Down Expand Up @@ -168,7 +169,7 @@ metanetwork <- function(
# =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= #
if (export) {
grDevices::png(
"metanetwork.png",
filename,
res = res,
width = img_size,
height = img_size,
Expand Down Expand Up @@ -238,4 +239,6 @@ metanetwork <- function(
textSize = textSize
)
}

invisible(filename)
}
22 changes: 13 additions & 9 deletions man/metanetwork.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
21 changes: 21 additions & 0 deletions tests/testthat/test-metanetwork.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
nodes <- metanetwork:::nodes
links <- metanetwork:::links
test_that("metanetwork error", {
expect_error(metanetwork(nodes[, -1], links, "Columns `network`"))
expect_error(metanetwork(nodes, links[, -1], "Columns `from`"))
expect_error(metanetwork(nodes, links, legend = TRUE, export = FALSE))
})

test_that("basic plot", {
# expect_snapshot_file(
# metanetwork(nodes, links, legend = FALSE, export = TRUE, res = 72),
# "metanetwork.png"
# )
# expect_snapshot_file(
# metanetwork(nodes, links, legend = TRUE, export = TRUE, res = 72),
# "metanetwork_legend.png"
# )
})

# unlink("metanetwork.png")
# unlink("metanetwork_legend.png")

0 comments on commit 498a78d

Please sign in to comment.