1
#' Graph from GEXF file
2
#'
3
#' Create a sigmajs graph from a GEXF file.
4
#'
5
#' @inheritParams sg_nodes
6
#' @param file Path to GEXF file.
7
#' @param sd A \link[crosstalk]{SharedData} of nodes.
8
#'
9
#' @examples
10
#' \dontrun{
11
#' gexf <- "https://gephi.org/gexf/data/yeast.gexf"
12
#' 
13
#' sigmajs() %>% 
14
#'   sg_from_gexf(gexf) 
15
#' }
16
#' 
17
#' @return A modified version of the \code{sg} object.
18
#' 
19
#' @export
20
sg_from_gexf <- function(sg, file, sd = NULL) {
21

22 1
	if (missing(sg))
23 1
		stop("missing sg", call. = FALSE)
24
  
25 1
  .test_sg(sg)
26
  
27 1
  if(missing(file))
28 1
    stop("missing file", call. = FALSE)
29
  
30 1
  if(!is.null(sd)){
31 1
    if (crosstalk::is.SharedData(sd)) {
32
      # crosstalk settings
33 1
      sg$x$crosstalk$crosstalk_key <- sd$key()
34 1
      sg$x$crosstalk$crosstalk_group <- sd$groupName()
35
    } 
36
  } 
37

38 1
  read <- suppressWarnings(readLines(file))
39 1
	data <- paste(read, collapse = "\n")
40

41 1
	sg$x$data <- data
42 1
	sg$x$gexf <- TRUE # indicate coming from GEXF file
43
	
44 1
	sg
45
}

Read our documentation on viewing source code .

Loading