Skip to content

Commit 2f915c2

Browse files
committed
added object checks to functions
1 parent 666a15b commit 2f915c2

9 files changed

+31
-0
lines changed

NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
### Minor improvements
88

99
- added a CONTRIBUTING.md file for contribution guidelines
10+
- added check to determine if input graph is an igraph object for all functions that need an igraph as input
11+
- added check to determine if input tree-ring dataset is rwl object for `sim_table`
1012

1113
### Bug Fixes
1214

R/clique_community_names.R

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@
2525
#' @importFrom magrittr %>%
2626

2727
clique_community_names <- function(g, k = 3) {
28+
if (!igraph::is.igraph(g)) {
29+
stop(paste0("Please use an igraph object as input. The current object is an ", class(g), "."))
30+
}
2831
if (k > igraph::clique_num(g)) {
2932
stop(paste0("The maximum clique size in the network is ", igraph::clique_num(g), ". Therefore k cannot exceed this number"))
3033
}

R/clique_community_names_par.R

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
#' @importFrom foreach %dopar%
3131

3232
clique_community_names_par <- function(g, k = 3, n_core = 4) {
33+
if (!igraph::is.igraph(g)) {
34+
stop(paste0("Please use an igraph object as input. The current object is an ", class(g), "."))
35+
}
3336
doParallel::registerDoParallel(cores = n_core)
3437
if (k > igraph::clique_num(g)) {
3538
stop(paste0("The maximum clique size in the network is ", igraph::clique_num(g), ". Therefore k cannot exceed this number"))

R/cyto_create_cpm_style.R

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ cyto_create_cpm_style <- function(graph_input, k = 3, com_k = NULL, style_name =
3030
if ("GreyNodesLabel" %in% RCy3::getVisualStyleNames() == FALSE) {
3131
RCy3::importVisualStyles(filename = system.file("extdata", "NetworkStyles.xml", package = "dendroNetwork"))
3232
}
33+
if (!igraph::is.igraph(graph_input)) {
34+
stop(paste0("Please use an igraph object as input. The current object is an ", class(graph_input), "."))
35+
}
3336
if (is.numeric(k)) {
3437
if (style_name == "auto") {
3538
style_name <- paste0(substitute(graph_input), "_CPM(k=", k, ")")

R/cyto_create_gn_style.R

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ cyto_create_gn_style <- function(graph_input, gn_coms = NULL, style_name = "auto
2828
if ("GreyNodesLabel" %in% RCy3::getVisualStyleNames() == FALSE) {
2929
RCy3::importVisualStyles(filename = system.file("extdata", "NetworkStyles.xml", package = "dendroNetwork"))
3030
}
31+
if (!igraph::is.igraph(graph_input)) {
32+
stop(paste0("Please use an igraph object as input. The current object is an ", class(graph_input), "."))
33+
}
3134
if (style_name == "auto") {
3235
style_name <- paste0(substitute(graph_input), "_GN")
3336
}

R/cyto_create_graph.R

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ cyto_create_graph <- function(graph_input,
3333
message("Cytoscape is not running, please start Cytoscape first")
3434
stop()
3535
}
36+
if (!igraph::is.igraph(graph_input)) {
37+
stop(paste0("Please use an igraph object as input. The current object is an ", class(graph_input), "."))
38+
}
3639
varnames <- all.vars(match.call())
3740
for (v in varnames) {
3841
if (!exists(v)) {

R/find_all_cpm_com.R

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818

1919
find_all_cpm_com <- function(graph_input, n_core = 0) {
20+
if (!igraph::is.igraph(graph_input)) {
21+
stop(paste0("Please use an igraph object as input. The current object is an ", class(graph_input), "."))
22+
}
2023
if (n_core > 1) {
2124
for (i in 3:igraph::clique_num(graph_input)) {
2225
com_cpm <- clique_community_names_par(graph_input, i, n_core)

R/gn_names.R

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
#' @importFrom magrittr %>%
1919

2020
gn_names <- function(g) {
21+
if (!igraph::is.igraph(g)) {
22+
stop(paste0("Please use an igraph object as input. The current object is an ", class(g), "."))
23+
}
2124
g_GN <- igraph::cluster_edge_betweenness(g,
2225
weights = igraph::E(g)$weight, directed = FALSE,
2326
edge.betweenness = TRUE, merges = TRUE, bridges = TRUE,

R/sim_table.R

+8
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ sim_table <- function(trs1,
3333
trs2 = NULL,
3434
min_overlap = 50,
3535
last_digit_radius = FALSE) {
36+
if (!("rwl" %in% class(trs1))) {
37+
stop(paste0("Please use an rwl object as input. The current first input object is a ", class(trs1), "."))
38+
}
39+
if (!is.null(trs2)) {
40+
if (!"rwl" %in% class(trs2)) {
41+
stop(paste0("Please use an rwl object as input. The current second input object is a ", class(trs2), "."))
42+
}
43+
}
3644
# nr of series in tree-ring series
3745
n1 <- dim(trs1)[2]
3846
if (is.null(trs2)) {

0 commit comments

Comments
 (0)