Skip to content

Commit

Permalink
Working on write print and plot
Browse files Browse the repository at this point in the history
  • Loading branch information
gvegayon committed Nov 6, 2017
1 parent 037e7a1 commit 9286830
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 21 deletions.
13 changes: 4 additions & 9 deletions R/methods.r
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,10 @@ print.gexf <- function(x, file=NA, replace=F, ...) {
################################################################################
# Printing method
################################################################################
if (is.na(file)) {
cat(x$graph)
}
else {
output <- file(description=file,open="w",encoding='UTF-8')
write(x$graph, file=output,...)
close.connection(output)
message('GEXF graph successfully written at:\n',normalizePath(file))
}
cat(x$graph)

invisible(x)

}

#' @name gexf-methods
Expand Down
1 change: 1 addition & 0 deletions R/plot.gexf.r
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ plot.gexf <- function(x, EdgeType=NULL, output.dir=NULL,...){

.Defunct("Gephi for visualizing")
}

2 changes: 1 addition & 1 deletion R/rgexf-package.r
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ NULL
#' # Summary and pring
#' summary(mygraph)
#'
#' print(mygraph, file="mygraph.gexf", replace=T)
#' write.gexf(mygraph, output="mygraph.gexf", replace=TRUE)
#'
#' # Plotting
#' plot(mygraph)
Expand Down
25 changes: 20 additions & 5 deletions R/rgexf.r
Original file line number Diff line number Diff line change
Expand Up @@ -738,15 +738,30 @@ gexf <- function(
if (is.na(output)) {
return(results)
} else {
print(results, file=output, replace=TRUE)
# warning("Starting version 0.17.0")
write.gexf(results, file=output, replace=TRUE)
}
}


#' @export
#' @rdname gexf-class
write.gexf <- function(...) {
warning("In future versions, rgexf 2.0, this function will be",
" the equivalent of -print(..., file=)-, and replaced by -gexf-")
gexf(...)
write.gexf <- function(nodes, ...) {

if (!inherits(nodes, "gexf")) {
gexf(nodes, ...)

} else if (length(list(...)$output)) {

output <- list(...)$output

f <- file(description = output, open="w",encoding='UTF-8')
write(nodes$graph, file=f)
close.connection(f)
message('GEXF graph successfully written at:\n',normalizePath(output))
return(invisible(nodes))

}
}


2 changes: 1 addition & 1 deletion demo/gexf.R
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ grafo <- gexf(nodes=people, edges=relations,
),
edgesAtt=edgetruefalse)

print(grafo)
grafo
4 changes: 2 additions & 2 deletions dependencies/DiagrammeR_0.9.2.log
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Checking the R package DiagrammeR version 0.9.2
rgexf version 0.17.0
2017-11-06 11:55:51
2017-11-06 14:33:25

--------------------------------------------------------------------------------

Expand All @@ -13,7 +13,7 @@ rgexf version 0.17.0
* checking for LF line-endings in source and make files and shell scripts
* checking for empty or unneeded directories
* building ‘DiagrammeR_0.9.2.tar.gz’
* using log directory ‘/tmp/RtmpHJOo31/DiagrammeR.Rcheck’
* using log directory ‘/tmp/RtmpFYFjzL/DiagrammeR.Rcheck’
* using R version 3.4.2 (2017-09-28)
* using platform: x86_64-pc-linux-gnu (64-bit)
* using session charset: UTF-8
Expand Down
2 changes: 1 addition & 1 deletion man/gexf-class.Rd

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

2 changes: 1 addition & 1 deletion man/gexf-methods.Rd

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

2 changes: 1 addition & 1 deletion vignettes/rgexf.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,5 @@ graph <- gexf(
position=rbind(pos,pos2,pos3))
)
print(graph)
graph
```

0 comments on commit 9286830

Please sign in to comment.