1gexf_version <- function(vers="1.3") {
2  # List of versions
3  VERS <- list(
4    `1.3` = list(
5      number               = "1.3",
6      xmlns                = "http://www.gexf.net/1.3",
7      `xsi:schemaLocation` = "http://www.gexf.net/1.3 http://www.gexf.net/1.3/gexf.xsd",
8      `xmlns:vis`          = "http://www.gexf.net/1.3/viz"
9    ),
10    `1.2` = list(
11      number               = "1.2",
12      xmlns                = "http://www.gexf.net/1.2draft",
13      `xsi:schemaLocation` = "http://www.gexf.net/1.2draft http://www.gexf.net/1.2draft/gexf.xsd",
14      `xmlns:vis`          = "http://www.gexf.net/1.2draft/viz"
15    ),
16    `1.1` = list(
17      number               = "1.1",
18      xmlns                = "http://www.gexf.net/1.1draft",
19      `xsi:schemaLocation` = "http://www.gexf.net/1.1draft http://www.gexf.net/1.1draft/gexf.xsd",
20      `xmlns:vis`          = "http://www.gexf.net/1.1draft/viz"
21    )
22  )
23
24  # Checking length
25
26
27  if (vers %in% names(VERS)) {
28    VERS[[vers]]
29  } else {
30    stop("version GEXF ",vers," not supported. Currently supported are: ",
31         paste(names(VERS), collapse=", "))
32  }
33}
34
35#' @importFrom XML xmlTreeParse xmlNode addChildren asXMLNode saveXML newXMLDoc
36#'  newXMLNode newXMLNamespace xmlAttrs parseXMLAndAdd
37#' @importFrom igraph get.data.frame list.vertex.attributes list.edge.attributes
38#'   E is.directed V set.vertex.attribute set.edge.attribute
39#' @importFrom grDevices rgb col2rgb colors
40#' @importFrom utils head
41#' @importFrom servr httd
42#' @importFrom stats complete.cases
43NULL
44
45#' Edge list with attributes
46#'
47#' Sample of accounts by December 2011.
48#'
49#'
50#' @name followers
51#' @docType data
52#' @format A data frame containing 6065 observations.
53#' @source Fabrega and Paredes (2012): \dQuote{La politica en 140 caracteres}
54#' en Intermedios: medios de comunicacion y democracia en Chile. Ediciones UDP
55#' @keywords datasets
56NULL
57
58
59
60
61
62#' S3 methods for \code{gexf} objects
63#'
64#' Methods to print and summarize \code{gexf} class objects
65#'
66#' \code{print.gexf} displays the graph (XML) in the console. If \code{file} is
67#' not \code{NA}, a GEXF file will be exported to the indicated filepath.
68#'
69#' \code{summay.gexf} prints summary statistics and information about the
70#' graph.
71#'
72#'
73#' @aliases print.gexf export-gexf summary.gexf
74#' @param x An \code{gexf} class object.
75#' @param object An \code{gexf} class object.
76#' @param file String. Output path where to save the GEXF file.
77#' @param replace Logical. If \code{file} exists, \code{TRUE} would replace the
78#' file.
79#' @param \dots Ignored
80#' @return \item{list("print.gexf")}{ None (invisible \code{NULL}).}
81#' \item{list("summary.gexf")}{ List containing some \code{gexf} object
82#' statistics.}
83#'
84#' @author George G. Vega Yon
85#'
86#' Joshua B. Kunst
87#' @seealso See also \code{\link{write.gexf}}, \code{\link{plot.gexf}}
88#' @keywords methods
89#' @examples
90#'
91#'   if (interactive()) {
92#'     # Data frame of nodes
93#'     people <- data.frame(id=1:4, label=c("juan", "pedro", "matthew", "carlos"),
94#'                      stringsAsFactors=F)
95#'
96#'     # Data frame of edges
97#'     relations <- data.frame(source=c(1,1,1,2,3,4,2,4,4),
98#'                         target=c(4,2,3,3,4,2,4,1,1))
99#'
100#'     # Building gexf graph
101#'     mygraph <- gexf(nodes=people, edges=relations)
102#'
103#'     # Summary and pring
104#'     summary(mygraph)
105#'
106#'     write.gexf(mygraph, output="mygraph.gexf", replace=TRUE)
107#'
108#'     # Plotting
109#'     plot(mygraph)
110#'
111#'   }
112#' @name gexf-methods
113NULL
114
115
116
117
118
119#' Build, Import and Export GEXF Graph Files
120#'
121#' Create, read and write GEXF (Graph Exchange XML Format) graph files (used in
122#' Gephi and others).
123#'
124#' Using the XML package, it allows the user to easily build/read graph files
125#' including attributes, GEXF viz attributes (such as color, size, and
126#' position), network dynamics (for both edges and nodes) and edge weighting.
127#'
128#' Users can build/handle graphs element-by-element or massively through
129#' data-frames, visualize the graph on a web browser through "gexf-js" (a
130#' javascript library) and interact with the igraph package.
131#'
132#' Finally, the functions \code{igraph.to.gexf} and \code{gexf.to.igraph}
133#' convert objects from \code{igraph} to \code{gexf} and viceversa keeping
134#' attributes and colors.
135#'
136#' Please visit the project home for more information:
137#' \url{https://github.com/gvegayon/rgexf}.
138#'
139#'
140#' @name rgexf-package
141#' @aliases rgexf-package rgexf gephi
142#' @docType package
143#' @note See the GEXF primer for details on the GEXF graph format:
144#' \url{https://gephi.org/gexf/1.2draft/gexf-12draft-primer.pdf}
145#' @references \itemize{ \item rgexf project site:
146#' \url{https://github.com/gvegayon/rgexf} \item Gephi project site:
147#' \url{https://gephi.org/} \item GEXF project site: \url{https://gephi.org/gexf/format//}
148#' \item gexf-js project website: \url{https://github.com/raphv/gexf-js}
149#' \item Sigmasj project site: \url{http://sigmajs.org/}
150#' }
151#' @keywords package
152#' @examples
153#'
154#' if (interactive()) {
155#'     demo(gexf) # Example of gexf command using fictional data.
156#'     demo(gexfattributes) # Working with attributes.
157#'     demo(gexfbasic) # Basic net.
158#'     demo(gexfdynamic) # Dynamic net.
159#'     demo(edge.list) # Working with edges lists.
160#'     demo(gexffull) # All the package.
161#'     demo(gexftwitter) # Example with real data of chilean twitter accounts.
162#'     demo(gexfdynamicandatt) # Dynamic net with static attributes.
163#'     demo(gexfbuildfromscratch) # Example building a net from scratch.
164#'     demo(gexfigraph) # Two-way gexf-igraph conversion
165#'     demo(gexfrandom) # A nice routine creating a good looking graph
166#' }
167#'
168NULL
169
170
171
172
173
174#' Twitter accounts of Chilean Politicians and Journalists (sample)
175#'
176#' Sample of accounts by December 2011.
177#'
178#'
179#' @name twitteraccounts
180#' @docType data
181#' @format A data frame containing 148 observations.
182#' @source Fabrega and Paredes (2012): \dQuote{La politica en 140 caracteres}
183#' en Intermedios: medios de comunicacion y democracia en Chile. Ediciones UDP
184#' @keywords datasets
185NULL
186
187
188
189