diff --git a/R/motifs.R b/R/motifs.R index 993a689c20..b66ad1dce8 100644 --- a/R/motifs.R +++ b/R/motifs.R @@ -24,7 +24,7 @@ triad.census <- function(graph) { # nocov start #' @inheritParams count_motifs #' @keywords internal #' @export -graph.motifs.no <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov start +graph.motifs.no <- function(graph, size = 3, cut.prob = NULL) { # nocov start lifecycle::deprecate_soft("2.0.0", "graph.motifs.no()", "count_motifs()") count_motifs(graph = graph, size = size, cut.prob = cut.prob) } # nocov end @@ -39,7 +39,7 @@ graph.motifs.no <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov #' @inheritParams sample_motifs #' @keywords internal #' @export -graph.motifs.est <- function(graph, size = 3, cut.prob = rep(0, size), sample.size = vcount(graph) / 10, sample = NULL) { # nocov start +graph.motifs.est <- function(graph, size = 3, cut.prob = NULL, sample.size = vcount(graph) / 10, sample = NULL) { # nocov start lifecycle::deprecate_soft("2.0.0", "graph.motifs.est()", "sample_motifs()") sample_motifs(graph = graph, size = size, cut.prob = cut.prob, sample.size = sample.size, sample = sample) } # nocov end @@ -54,7 +54,7 @@ graph.motifs.est <- function(graph, size = 3, cut.prob = rep(0, size), sample.si #' @inheritParams motifs #' @keywords internal #' @export -graph.motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { # nocov start +graph.motifs <- function(graph, size = 3, cut.prob = NULL) { # nocov start lifecycle::deprecate_soft("2.0.0", "graph.motifs()", "motifs()") motifs(graph = graph, size = size, cut.prob = cut.prob) } # nocov end @@ -110,7 +110,7 @@ dyad.census <- function(graph) { # nocov start #' directed graphs and sizes 3-6 in undirected graphs. #' @param cut.prob Numeric vector giving the probabilities that the search #' graph is cut at a certain level. Its length should be the same as the size -#' of the motif (the `size` argument). By default no cuts are made. +#' of the motif (the `size` argument). If `NULL`, the default, no cuts are made. #' @return `motifs()` returns a numeric vector, the number of occurrences of #' each motif in the graph. The motifs are ordered by their isomorphism #' classes. Note that for unconnected subgraphs, which are not considered to be @@ -125,10 +125,10 @@ dyad.census <- function(graph) { # nocov start #' motifs(g, 3) #' count_motifs(g, 3) #' sample_motifs(g, 3) -motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { +motifs <- function(graph, size = 3, cut.prob = NULL) { ensure_igraph(graph) + if (!is.null(cut.prob) && length(cut.prob) != size) { cut.prob <- as.numeric(cut.prob) - if (length(cut.prob) != size) { cut.prob <- c( cut.prob[-length(cut.prob)], rep(cut.prob[-length(cut.prob)], length(cut.prob) - 1) @@ -136,10 +136,17 @@ motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { } on.exit(.Call(R_igraph_finalizer)) - res <- .Call( - R_igraph_motifs_randesu, graph, as.numeric(size), - as.numeric(cut.prob) - ) + if (is.null(cut.prob)) { + res <- .Call( + R_igraph_motifs_randesu, graph, as.numeric(size), + NULL + ) + } else { + res <- .Call( + R_igraph_motifs_randesu, graph, as.numeric(size), + as.numeric(cut.prob) + ) + } res[is.nan(res)] <- NA res } @@ -156,7 +163,7 @@ motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { #' @param size The size of the motif. #' @param cut.prob Numeric vector giving the probabilities that the search #' graph is cut at a certain level. Its length should be the same as the size -#' of the motif (the `size` argument). By default no cuts are made. +#' of the motif (the `size` argument). If `NULL`, the default, no cuts are made. #' @return `count_motifs()` returns a numeric scalar. #' @seealso [isomorphism_class()] #' @@ -168,10 +175,10 @@ motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { #' motifs(g, 3) #' count_motifs(g, 3) #' sample_motifs(g, 3) -count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { +count_motifs <- function(graph, size = 3, cut.prob = NULL) { ensure_igraph(graph) + if (!is.null(cut.prob) && length(cut.prob) != size) { cut.prob <- as.numeric(cut.prob) - if (length(cut.prob) != size) { cut.prob <- c( cut.prob[-length(cut.prob)], rep(cut.prob[-length(cut.prob)], length(cut.prob) - 1) @@ -179,10 +186,17 @@ count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { } on.exit(.Call(R_igraph_finalizer)) - .Call( - R_igraph_motifs_randesu_no, graph, as.numeric(size), - as.numeric(cut.prob) - ) + if (is.null(cut.prob)) { + .Call( + R_igraph_motifs_randesu_no, graph, as.numeric(size), + NULL + ) + } else { + .Call( + R_igraph_motifs_randesu_no, graph, as.numeric(size), + as.numeric(cut.prob) + ) + } } #' Graph motifs @@ -198,7 +212,7 @@ count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { #' in directed graphs and sizes 3-6 in undirected graphs. #' @param cut.prob Numeric vector giving the probabilities that the search #' graph is cut at a certain level. Its length should be the same as the size -#' of the motif (the `size` argument). By default no cuts are made. +#' of the motif (the `size` argument). If `NULL`, the default, no cuts are made. #' @param sample.size The number of vertices to use as a starting point for #' finding motifs. Only used if the `sample` argument is `NULL`. #' @param sample If not `NULL` then it specifies the vertices to use as a @@ -215,11 +229,11 @@ count_motifs <- function(graph, size = 3, cut.prob = rep(0, size)) { #' motifs(g, 3) #' count_motifs(g, 3) #' sample_motifs(g, 3) -sample_motifs <- function(graph, size = 3, cut.prob = rep(0, size), +sample_motifs <- function(graph, size = 3, cut.prob = NULL, sample.size = vcount(graph) / 10, sample = NULL) { ensure_igraph(graph) + if (!is.null(cut.prob) && length(cut.prob) != size) { cut.prob <- as.numeric(cut.prob) - if (length(cut.prob) != size) { cut.prob <- c( cut.prob[-length(cut.prob)], rep(cut.prob[-length(cut.prob)], length(cut.prob) - 1) diff --git a/man/count_motifs.Rd b/man/count_motifs.Rd index 3952cb1ccb..d9ef9fed7e 100644 --- a/man/count_motifs.Rd +++ b/man/count_motifs.Rd @@ -4,7 +4,7 @@ \alias{count_motifs} \title{Graph motifs} \usage{ -count_motifs(graph, size = 3, cut.prob = rep(0, size)) +count_motifs(graph, size = 3, cut.prob = NULL) } \arguments{ \item{graph}{Graph object, the input graph.} @@ -13,7 +13,7 @@ count_motifs(graph, size = 3, cut.prob = rep(0, size)) \item{cut.prob}{Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size -of the motif (the \code{size} argument). By default no cuts are made.} +of the motif (the \code{size} argument). If \code{NULL}, the default, no cuts are made.} } \value{ \code{count_motifs()} returns a numeric scalar. diff --git a/man/graph.motifs.Rd b/man/graph.motifs.Rd index 00ff37371b..fd92d7bf43 100644 --- a/man/graph.motifs.Rd +++ b/man/graph.motifs.Rd @@ -4,7 +4,7 @@ \alias{graph.motifs} \title{Graph motifs} \usage{ -graph.motifs(graph, size = 3, cut.prob = rep(0, size)) +graph.motifs(graph, size = 3, cut.prob = NULL) } \arguments{ \item{graph}{Graph object, the input graph.} @@ -14,7 +14,7 @@ directed graphs and sizes 3-6 in undirected graphs.} \item{cut.prob}{Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size -of the motif (the \code{size} argument). By default no cuts are made.} +of the motif (the \code{size} argument). If \code{NULL}, the default, no cuts are made.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/graph.motifs.est.Rd b/man/graph.motifs.est.Rd index 82dce6287d..e9de4a5f29 100644 --- a/man/graph.motifs.est.Rd +++ b/man/graph.motifs.est.Rd @@ -7,7 +7,7 @@ graph.motifs.est( graph, size = 3, - cut.prob = rep(0, size), + cut.prob = NULL, sample.size = vcount(graph)/10, sample = NULL ) @@ -20,7 +20,7 @@ in directed graphs and sizes 3-6 in undirected graphs.} \item{cut.prob}{Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size -of the motif (the \code{size} argument). By default no cuts are made.} +of the motif (the \code{size} argument). If \code{NULL}, the default, no cuts are made.} \item{sample.size}{The number of vertices to use as a starting point for finding motifs. Only used if the \code{sample} argument is \code{NULL}.} diff --git a/man/graph.motifs.no.Rd b/man/graph.motifs.no.Rd index 238fedc1b4..b31fd7804a 100644 --- a/man/graph.motifs.no.Rd +++ b/man/graph.motifs.no.Rd @@ -4,7 +4,7 @@ \alias{graph.motifs.no} \title{Graph motifs} \usage{ -graph.motifs.no(graph, size = 3, cut.prob = rep(0, size)) +graph.motifs.no(graph, size = 3, cut.prob = NULL) } \arguments{ \item{graph}{Graph object, the input graph.} @@ -13,7 +13,7 @@ graph.motifs.no(graph, size = 3, cut.prob = rep(0, size)) \item{cut.prob}{Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size -of the motif (the \code{size} argument). By default no cuts are made.} +of the motif (the \code{size} argument). If \code{NULL}, the default, no cuts are made.} } \description{ \ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#deprecated}{\figure{lifecycle-deprecated.svg}{options: alt='[Deprecated]'}}}{\strong{[Deprecated]}} diff --git a/man/motifs.Rd b/man/motifs.Rd index 0ad6157b7e..d6c2208d0e 100644 --- a/man/motifs.Rd +++ b/man/motifs.Rd @@ -4,7 +4,7 @@ \alias{motifs} \title{Graph motifs} \usage{ -motifs(graph, size = 3, cut.prob = rep(0, size)) +motifs(graph, size = 3, cut.prob = NULL) } \arguments{ \item{graph}{Graph object, the input graph.} @@ -14,7 +14,7 @@ directed graphs and sizes 3-6 in undirected graphs.} \item{cut.prob}{Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size -of the motif (the \code{size} argument). By default no cuts are made.} +of the motif (the \code{size} argument). If \code{NULL}, the default, no cuts are made.} } \value{ \code{motifs()} returns a numeric vector, the number of occurrences of diff --git a/man/sample_motifs.Rd b/man/sample_motifs.Rd index 3d9eac4f8e..9ec6722a7a 100644 --- a/man/sample_motifs.Rd +++ b/man/sample_motifs.Rd @@ -7,7 +7,7 @@ sample_motifs( graph, size = 3, - cut.prob = rep(0, size), + cut.prob = NULL, sample.size = vcount(graph)/10, sample = NULL ) @@ -20,7 +20,7 @@ in directed graphs and sizes 3-6 in undirected graphs.} \item{cut.prob}{Numeric vector giving the probabilities that the search graph is cut at a certain level. Its length should be the same as the size -of the motif (the \code{size} argument). By default no cuts are made.} +of the motif (the \code{size} argument). If \code{NULL}, the default, no cuts are made.} \item{sample.size}{The number of vertices to use as a starting point for finding motifs. Only used if the \code{sample} argument is \code{NULL}.}