Skip to content

Commit

Permalink
Merge pull request #95 from stocnet/develop
Browse files Browse the repository at this point in the history
v1.2.4
  • Loading branch information
jhollway authored Oct 5, 2024
2 parents ee16b13 + 98c53fe commit 6c76a04
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 28 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: manynet
Title: Many Ways to Make, Modify, Map, Mark, and Measure Myriad Networks
Version: 1.2.3
Version: 1.2.4
Date: 2024-10-05
Description: Many tools for making, modifying, mapping, marking, measuring,
and motifs and memberships of many different types of networks.
Expand All @@ -11,12 +11,12 @@ Description: Many tools for making, modifying, mapping, marking, measuring,
and describing and visualizing networks with sensible defaults.
URL: https://stocnet.github.io/manynet/
BugReports: https://github.com/stocnet/manynet/issues
Depends: R (>= 3.6.0)
License: MIT + file LICENSE
Language: en-GB
Encoding: UTF-8
LazyData: true
RoxygenNote: 7.3.2
Depends: R (>= 3.6.0)
Imports:
cli,
dplyr (>= 1.1.0),
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
# manynet 1.2.4

## Package

- Fixed `thisRequires()` bug by testing for interactivity
- Dropped brokerage census examples

## Modifying

- Improved `to_ego()` and `to_egos()` to specify direction

# manynet 1.2.3

## Mapping
Expand Down
19 changes: 12 additions & 7 deletions R/manip_reformed.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,24 @@ NULL
#' By default 0.
#' Increasing this to 1 excludes the ego,
#' and 2 excludes ego's direct alters.
#' @param direction String, either "out" or "in".
#' @export
to_ego <- function(.data, node, max_dist = 1, min_dist = 0) UseMethod("to_ego")
to_ego <- function(.data, node, max_dist = 1, min_dist = 0,
direction = c("out","in")) UseMethod("to_ego")

#' @export
to_ego.igraph <- function(.data, node, max_dist = 1, min_dist = 0){
egos <- to_egos(.data, max_dist = max_dist, min_dist = min_dist)
to_ego.igraph <- function(.data, node, max_dist = 1, min_dist = 0,
direction = c("out","in")){
egos <- to_egos(.data, max_dist = max_dist, min_dist = min_dist,
direction = direction)
as_igraph(egos[[node]])
}

#' @export
to_ego.tbl_graph <- function(.data, node, max_dist = 1, min_dist = 0){
egos <- to_egos(.data, max_dist = max_dist, min_dist = min_dist)
to_ego.tbl_graph <- function(.data, node, max_dist = 1, min_dist = 0,
direction = c("out","in")){
egos <- to_egos(.data, max_dist = max_dist, min_dist = min_dist,
direction = direction)
as_tidygraph(egos[[node]])
}

Expand Down Expand Up @@ -459,7 +465,7 @@ to_blocks.tbl_graph <- function(.data, membership, FUN = mean){
#' ```
#' @name manip_paths
#' @family modifications
#' @inheritParams manip_reformat
#' @inheritParams manip_scope
#' @returns
#' All `to_` functions return an object of the same class as that provided.
#' So passing it an igraph object will return an igraph object
Expand Down Expand Up @@ -658,7 +664,6 @@ to_tree <- function(.data) {

#' @rdname manip_paths
#' @param from The index or name of the node from which the path should be traced.
#' @param direction String, either "out" or "in".
#' @export
to_dominating <- function(.data, from, direction = c("out","in")) {
direction <- match.arg(direction)
Expand Down
29 changes: 18 additions & 11 deletions R/manip_split.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,20 @@ NULL
#' @export
to_egos <- function(.data,
max_dist = 1,
min_dist = 0) UseMethod("to_egos")
min_dist = 0,
direction = c("out","in")) UseMethod("to_egos")

#' @export
to_egos.igraph <- function(.data,
max_dist = 1,
min_dist = 0){
min_dist = 0,
direction = c("out","in")){
if(is_twomode(.data)) max_dist <- max_dist*2
mnet_progress_step("Obtaining neighbourhoods")
out <- igraph::make_ego_graph(.data,
order = max_dist,
mindist = min_dist)
mindist = min_dist,
mode = match.arg(direction))
if(is_labelled(.data))
names(out) <- node_names(.data)
out
Expand All @@ -44,40 +47,44 @@ to_egos.igraph <- function(.data,
#' @export
to_egos.tbl_graph <- function(.data,
max_dist = 1,
min_dist = 0){
min_dist = 0,
direction = c("out","in")){
out <- to_egos(as_igraph(.data),
max_dist,
min_dist)
min_dist, direction)
lapply(out, function(x) as_tidygraph(x))
}

#' @export
to_egos.network <- function(.data,
max_dist = 1,
min_dist = 0){
min_dist = 0,
direction = c("out","in")){
out <- to_egos(as_igraph(.data),
max_dist,
min_dist)
min_dist, direction)
lapply(out, function(x) as_network(x))
}

#' @export
to_egos.matrix <- function(.data,
max_dist = 1,
min_dist = 0){
min_dist = 0,
direction = c("out","in")){
out <- to_egos(as_igraph(.data),
max_dist,
min_dist)
min_dist, direction)
lapply(out, function(x) as_matrix(x))
}

#' @export
to_egos.data.frame <- function(.data,
max_dist = 1,
min_dist = 0){
min_dist = 0,
direction = c("out","in")){
out <- to_egos(as_igraph(.data),
max_dist,
min_dist)
min_dist, direction)
lapply(out, function(x) as_edgelist(x))
}

Expand Down
4 changes: 2 additions & 2 deletions R/manynet-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ available_methods <- function(fun_vctr) {

# Helper function for checking and downloading packages
thisRequires <- function(pkgname){
if (!requireNamespace(pkgname, quietly = TRUE)) {
if (!requireNamespace(pkgname, quietly = TRUE) & interactive()) {
if(utils::askYesNo(msg = paste("The", pkgname,
"package is required to run this function. Would you like to install", pkgname, "from CRAN?"))) {
utils::install.packages(pkgname)
Expand All @@ -27,7 +27,7 @@ thisRequires <- function(pkgname){
}

thisRequiresBio <- function(pkgname) {
if (!requireNamespace(pkgname, quietly = TRUE)) {
if (!requireNamespace(pkgname, quietly = TRUE) & interactive()) {
if(utils::askYesNo(msg = paste("The", pkgname,
"package is required to run this function. Would you like to install", pkgname, "from BioConductor?"))) {
thisRequires("BiocManager")
Expand Down
4 changes: 2 additions & 2 deletions R/motif_census.R
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ NULL
#' _Social Networks_ 41:36–47.
#' \doi{10.1016/j.socnet.2014.11.005}
#' @examples
#' node_by_brokerage(manynet::ison_networkers, "Discipline")
#' # node_by_brokerage(ison_networkers, "Discipline")
#' @export
node_by_brokerage <- function(.data, membership, standardized = FALSE){
thisRequires("sna")
Expand All @@ -507,7 +507,7 @@ node_by_brokerage <- function(.data, membership, standardized = FALSE){

#' @rdname motif_brokerage
#' @examples
#' net_by_brokerage(ison_networkers, "Discipline")
#' # net_by_brokerage(ison_networkers, "Discipline")
#' @export
net_by_brokerage <- function(.data, membership, standardized = FALSE){
thisRequires("sna")
Expand Down
4 changes: 3 additions & 1 deletion man/manip_scope.Rd

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

4 changes: 3 additions & 1 deletion man/manip_split.Rd

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

4 changes: 2 additions & 2 deletions man/motif_brokerage.Rd

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

0 comments on commit 6c76a04

Please sign in to comment.