Skip to content

Commit

Permalink
resolving imports
Browse files Browse the repository at this point in the history
  • Loading branch information
ezufall committed Nov 8, 2024
1 parent e06d1ed commit 446b450
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 13 deletions.
23 changes: 21 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ export(pdf_clean)
export(textnet_extract)
export(top_features)
import(data.table)
import(dplyr)
import(igraph)
importFrom(R.utils,gunzip)
importFrom(data.table,rbindlist)
importFrom(data.table,setDT)
Expand All @@ -22,6 +20,27 @@ importFrom(dplyr,desc)
importFrom(dplyr,filter)
importFrom(dplyr,group_by)
importFrom(dplyr,left_join)
importFrom(dplyr,summarize)
importFrom(igraph,E)
importFrom(igraph,V)
importFrom(igraph,as.undirected)
importFrom(igraph,as_data_frame)
importFrom(igraph,cluster_louvain)
importFrom(igraph,degree)
importFrom(igraph,delete.edges)
importFrom(igraph,delete.vertices)
importFrom(igraph,delete_edge_attr)
importFrom(igraph,edge_attr)
importFrom(igraph,edge_attr_names)
importFrom(igraph,graph_from_data_frame)
importFrom(igraph,head_of)
importFrom(igraph,is.loop)
importFrom(igraph,modularity)
importFrom(igraph,reciprocity)
importFrom(igraph,simplify)
importFrom(igraph,strength)
importFrom(igraph,tail_of)
importFrom(igraph,vertex_attr)
importFrom(magrittr,"%>%")
importFrom(methods,is)
importFrom(network,network)
Expand Down
9 changes: 7 additions & 2 deletions R/combine_networks.R
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
#'
#' @return Single igraph object that consolidates nodes and edges from input graphs. If there are multiple nodes with the same name and different attributes originating from different graphs, this function preserves the node attributes associated with the version that appears most commonly. Adds a node attribute num_graphs_in, which denotes the number of input graphs each node was found in. For a weighted graph, the weight is equal to the original number of edges between the respective source and target nodes. Edge attributes for a multiplex graph are described in the help file of textnet_extract.
#' @importFrom data.table rbindlist
#' @import igraph
#' @importFrom igraph as_data_frame
#' @importFrom igraph graph_from_data_frame
#' @importFrom igraph edge_attr_names
#' @importFrom igraph delete_edge_attr
#' @importFrom igraph E
#' @importFrom igraph simplify
#' @importFrom methods is
#' @export
#'
Expand Down Expand Up @@ -59,7 +64,7 @@ combine_networks <- function(textnet_igraphs, mode = c('multiplex','weighted')){
superedges <- vector(mode = "list", length = length(num_graphs))
for(m in 1:num_graphs){
single_ig <- textnet_igraphs[[m]]
sidf <- get.data.frame(single_ig, what = "both")
sidf <- igraph::as_data_frame(single_ig, what = "both")
supernodes[[m]] <- sidf$vertices
superedges[[m]] <- sidf$edges
}
Expand Down
23 changes: 21 additions & 2 deletions R/export_to_network.R
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,26 @@
#' \item num_communities -- number of communities using louvain cluster algorithm on a weighted, undirected, non-multiplex version of the network
#' \item percent_vbn, percent_vbg, percent_vpb, percent_vbd, percent_vb, percent_vbz -- percent of edges in the graph that are of the respective verb tense
#' }
#' @import igraph
#' @importFrom igraph delete_edge_attr
#' @importFrom igraph delete.edges
#' @importFrom igraph E
#' @importFrom igraph edge_attr
#' @importFrom igraph edge_attr_names
#' @importFrom igraph head_of
#' @importFrom igraph tail_of
#' @importFrom igraph strength
#' @importFrom igraph reciprocity
#' @importFrom igraph cluster_louvain
#' @importFrom igraph modularity
#' @importFrom igraph V
#' @importFrom igraph delete.vertices
#' @importFrom igraph vertex_attr
#' @importFrom igraph graph_from_data_frame
#' @importFrom igraph is.loop
#' @importFrom igraph simplify
#' @importFrom igraph degree
#' @importFrom igraph as_data_frame
#' @importFrom igraph as.undirected
#' @importFrom dplyr filter
#' @importFrom network network network.size network.edgecount network.density
#' @importFrom sna connectedness centralization gtrans
Expand Down Expand Up @@ -117,7 +136,7 @@ export_to_network <- function(textnet_extract, export_format, keep_isolates=T, c
}

#network object
agency_df <- igraph::get.data.frame(igr, what = "both")
agency_df <- igraph::as_data_frame(igr, what = "both")
if(keep_isolates==T & collapse_edges == F){
#keep_all
net <- network::network(x=agency_df$edges, directed = T,
Expand Down
13 changes: 9 additions & 4 deletions R/top_features.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
#' @importFrom network network
#' @importFrom ohenery normalize
#' @importFrom tidyr tibble
#' @import dplyr
#' @import igraph
#' @importFrom dplyr group_by
#' @importFrom dplyr summarize
#' @importFrom dplyr arrange
#' @importFrom dplyr desc
#' @importFrom igraph degree
#' @importFrom igraph edge_attr
#' @importFrom igraph as_data_frame
#'
#' @export

Expand All @@ -36,7 +41,7 @@ top_features <- function(files, from_file=F){
}else{
igr <- files[[i]]
}
igr_df <- igraph::get.data.frame(igr, what = "both")
igr_df <- igraph::as_data_frame(igr, what = "both")

net <- network::network(x=igr_df$edges[,1:2], directed = T,
hyper = F, loops = T, multiple = T,
Expand All @@ -45,7 +50,7 @@ top_features <- function(files, from_file=F){


all_entities[[i]] <- sort(igraph::degree(igr),decreasing = T)
all_lemmas[[i]] <- sort(table(igraph::get.edge.attribute(
all_lemmas[[i]] <- sort(table(igraph::edge_attr(
igr, "head_verb_lemma")), decreasing = T)
}

Expand Down
7 changes: 4 additions & 3 deletions vignettes/textNet_vignette_2024.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,8 @@ We can now use these data structures to calculate node statistics, as printed be
```{r step8b2}
paths2 <- diag(old_mat %*% old_mat)
recip <- 2*paths2 / sna::degree(old_net)
totalCC <- as.vector(unname(DirectedClustering::ClustF(old_mat, type = "directed",
isolates="zero")$totalCC))
totalCC <- as.vector(unname(DirectedClustering::ClustF(old_mat,
type = "directed", isolates="zero")$totalCC))
closens <- sna::closeness(old_net, gmode = "graph", cmode="suminvundir")
between <- sna::betweenness(old_net,gmode = "graph",cmode="undirected")
deg <- sna::degree(old_net, gmode = "graph", cmode = "undirected")
Expand All @@ -337,7 +337,8 @@ We can now use these data structures to calculate node statistics, as printed be
paths2 <- diag(new_mat %*% new_mat)
recip <- 2*paths2 / sna::degree(new_net)
totalCC <- as.vector(unname(DirectedClustering::ClustF(new_mat, type = "directed", isolates="zero")$totalCC))
totalCC <- as.vector(unname(DirectedClustering::ClustF(new_mat,
type = "directed", isolates="zero")$totalCC))
closens <- sna::closeness(new_net, gmode = "graph", cmode="suminvundir")
between <- sna::betweenness(new_net,gmode = "graph",cmode="undirected")
deg <- sna::degree(new_net, gmode = "graph", cmode = "undirected")
Expand Down
Binary file modified vignettes/textNet_vignette_2024.pdf
Binary file not shown.

0 comments on commit 446b450

Please sign in to comment.