Ecological-Complexity-Lab / infomap_ecology_package

Package with functions to handle network data and run Infomap, inspired by ecological networks
25 stars 2 forks source link

create_infomap_linklist does not standardize column names #6

Closed shainova closed 4 years ago

shainova commented 4 years ago

Need to add the line names(edge_list)[1:2] <- c('from','to') to be able to join the edge list in the next command

shainova commented 4 years ago

The corrected function should be:

create_infomap_linklist <- 
function (x, make_directed = F, write_to_file = F, output_file = "infomap_link_list.txt") {
  if (class(x) != "monolayer") {
    stop("x must be of class monolayer")
  }

  edge_list <- x$edge_list
  names(edge_list)[1:2] <- c('from','to')

  nodes <- x$nodes
  edge_list %<>% left_join(nodes, by = c(from = "node_name")) %>% 
    left_join(nodes, by = c(to = "node_name")) %>% select(from = node_id.x, 
                                                          to = node_id.y, weight)
  if (write_to_file) {
    print(paste("Link list written to: ", output_file, sep = ""))
    write_delim(edge_list, output_file, delim = " ", col_names = F)
  }
  out <- list(edge_list_infomap = edge_list, nodes = nodes)
  class(out) <- "infomap_link_list"
  return(out)
}
shainova commented 4 years ago

fixed