Skip to content

Commit

Permalink
Fixing R CMD check
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Jun 27, 2024
1 parent 53ded69 commit cf10002
Show file tree
Hide file tree
Showing 5 changed files with 195 additions and 16 deletions.
5 changes: 4 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
# netplot 0.2-9999

* Unvalid arguments passed to `nplot()` now raise an error.
* Invalid arguments passed to `nplot()` now raise an error.

* Figures with legends are not drawn twice.

* Values supported by `nplot()` are now included in all methods (helps with
argument completion).


# netplot 0.2-0

Expand Down
8 changes: 8 additions & 0 deletions R/attribute-extraction.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#' @param graph A graph object of class igraph or network.
#' @param attribute A character string specifying the name of the attribute.
#' @return A vector of the attribute values. If the attribute does not exist, an error is thrown.
#' @keywords internal
#' @noRd
get_vertex_attribute <- function(graph, attribute) UseMethod("get_vertex_attribute")

#' @keywords internal
get_vertex_attribute.igraph <- function(graph, attribute) {

# Check if the attribute exists
Expand All @@ -17,6 +19,7 @@ get_vertex_attribute.igraph <- function(graph, attribute) {

}

#' @keywords internal
get_vertex_attribute.network <- function(graph, attribute) {

# Check if the attribute exists
Expand All @@ -29,14 +32,17 @@ get_vertex_attribute.network <- function(graph, attribute) {

}

#' @keywords internal
get_vertex_attribute.default <- function(graph, attribute) {

stop("Graph type not supported")

}

#' @keywords internal
get_edge_attribute <- function(graph, attribute) UseMethod("get_edge_attribute")

#' @keywords internal
get_edge_attribute.igraph <- function(graph, attribute) {

# Check if the attribute exists
Expand All @@ -49,6 +55,7 @@ get_edge_attribute.igraph <- function(graph, attribute) {

}

#' @keywords internal
get_edge_attribute.network <- function(graph, attribute) {

# Check if the attribute exists
Expand All @@ -61,6 +68,7 @@ get_edge_attribute.network <- function(graph, attribute) {

}

#' @keywords internal
get_edge_attribute.default <- function(graph, attribute) {

stop("Graph type not supported")
Expand Down
4 changes: 4 additions & 0 deletions R/color_nodes_function.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#' @keywords internal
color_nodes <- function(...) UseMethod("color_nodes")

#' @keywords internal
color_nodes.formula <- function(formula, ...) {

# Extract the LHS of the formula
Expand All @@ -18,6 +20,7 @@ color_nodes.formula <- function(formula, ...) {

}

#' @keywords internal
color_nodes.default <- function(
graph,
attribute,
Expand Down Expand Up @@ -137,6 +140,7 @@ color_nodes.default <- function(

#' @noRd
#' @importFrom stats quantile
#' @keywords internal
color_nodes_legend <- function(object) {

# Extracting the fill legend
Expand Down
106 changes: 94 additions & 12 deletions R/netplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,37 @@ nplot <- function(
#' @rdname nplot
nplot.igraph <- function(
x,
layout = igraph::layout_nicely(x),
vertex.size = igraph::degree(x, mode="in"),
vertex.label = igraph::vertex_attr(x, "name"),
edge.width = igraph::edge_attr(x, "weight"),
skip.arrows = !igraph::is_directed(x),
layout = igraph::layout_nicely(x),
vertex.size = igraph::degree(x, mode="in"),
bg.col = "transparent",
vertex.nsides = 10,
vertex.color = grDevices::hcl.colors(1),
vertex.size.range = c(.01, .03),
vertex.frame.color = NULL,
vertex.rot = 0,
vertex.frame.prop = .2,
vertex.label = igraph::vertex_attr(x, "name"),
vertex.label.fontsize = NULL,
vertex.label.color = "black",
vertex.label.fontfamily = "HersheySans",
vertex.label.fontface = "bold",
vertex.label.show = .3,
vertex.label.range = c(5, 15),
edge.width = igraph::edge_attr(x, "weight"),
edge.width.range = c(1, 2),
edge.arrow.size = NULL,
edge.color = ~ ego(alpha = .1, col = "gray") + alter,
edge.curvature = pi/3,
edge.line.lty = "solid",
edge.line.breaks = 5,
sample.edges = 1,
skip.vertex = FALSE,
skip.edges = FALSE,
skip.arrows = !igraph::is_directed(x),
add = FALSE,
zero.margins = TRUE,
...,
edgelist = NULL
edgelist
) {

if (!length(edge.width))
Expand All @@ -173,12 +197,37 @@ nplot.igraph <- function(
#' @importFrom sna gplot.layout.kamadakawai
nplot.network <- function(
x,
layout = sna::gplot.layout.kamadakawai(x, NULL),
vertex.size = sna::degree(x, cmode="indegree"),
vertex.label = network::get.vertex.attribute(x, "vertex.names"),
skip.arrows = !network::is.directed(x),
layout = sna::gplot.layout.kamadakawai(x, NULL),
vertex.size = sna::degree(x, cmode="indegree"),
bg.col = "transparent",
vertex.nsides = 10,
vertex.color = grDevices::hcl.colors(1),
vertex.size.range = c(.01, .03),
vertex.frame.color = NULL,
vertex.rot = 0,
vertex.frame.prop = .2,
vertex.label = network::get.vertex.attribute(x, "vertex.names"),
vertex.label.fontsize = NULL,
vertex.label.color = "black",
vertex.label.fontfamily = "HersheySans",
vertex.label.fontface = "bold",
vertex.label.show = .3,
vertex.label.range = c(5, 15),
edge.width = 1,
edge.width.range = c(1, 2),
edge.arrow.size = NULL,
edge.color = ~ ego(alpha = .1, col = "gray") + alter,
edge.curvature = pi/3,
edge.line.lty = "solid",
edge.line.breaks = 5,
sample.edges = 1,
skip.vertex = FALSE,
skip.edges = FALSE,
skip.arrows = !network::is.directed(x),
add = FALSE,
zero.margins = TRUE,
...,
edgelist = NULL
edgelist
) {

nplot.default(
Expand All @@ -196,7 +245,40 @@ nplot.network <- function(
#' @export
#' @rdname nplot
#' @importFrom igraph graph_from_adjacency_matrix
nplot.matrix <- function(x, ..., edgelist = NULL) {
nplot.matrix <- function(
x,
layout,
vertex.size = 1,
bg.col = "transparent",
vertex.nsides = 10,
vertex.color = grDevices::hcl.colors(1),
vertex.size.range = c(.01, .03),
vertex.frame.color = NULL,
vertex.rot = 0,
vertex.frame.prop = .2,
vertex.label = NULL,
vertex.label.fontsize = NULL,
vertex.label.color = "black",
vertex.label.fontfamily = "HersheySans",
vertex.label.fontface = "bold",
vertex.label.show = .3,
vertex.label.range = c(5, 15),
edge.width = 1,
edge.width.range = c(1, 2),
edge.arrow.size = NULL,
edge.color = ~ ego(alpha = .1, col = "gray") + alter,
edge.curvature = pi/3,
edge.line.lty = "solid",
edge.line.breaks = 5,
sample.edges = 1,
skip.vertex = FALSE,
skip.edges = FALSE,
skip.arrows = skip.edges,
add = FALSE,
zero.margins = TRUE,
...,
edgelist
) {

nplot.igraph(
x = igraph::graph_from_adjacency_matrix(x),
Expand Down
88 changes: 85 additions & 3 deletions man/nplot.Rd

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

0 comments on commit cf10002

Please sign in to comment.