最后,我希望使用RNetLogo将一个NetLogo网络传递给R,这样R就可以使用包或influenceR进行一些网络分析,然后将结果传回给NetLogo。我目前正在分别运行NetLogo和R,以便在将R代码放入RNetLogo所需的格式之前确保其工作正常。
我正在创建NetLogo中的网络,并将其传递给igraph,但是iGraph对于图形格式却是情绪化的。最好的传输格式似乎是gml,但是用于保存gml的NetLogo网络扩展并不能满足igraph的要求。
我编写了一个简单的gml导出。看上去:
to export-simple-gml
carefully [ file-delete "temp.gml" ] [ ]
file-open "temp.gml"
file-print "graph" file-print "["
file-print " directed 0"
ask turtles
[ file-print " node" file-print " ["
file-type " id " file-print who
file-print " ]"
]
ask links
[ let source one-of both-ends
let target [other-end] of source
file-print " edge" file-print " ["
file-type " source " file-print [who] of source
file-type " target " file-print [who] of target
file-print " ]"
]
file-print "]"
file-close
endR导入代码非常简单:
library(igraph)
gg <- read_graph(file = "temp.gml", format = "gml")如果我在运行NetLogo函数时关闭了R,然后关闭NetLogo并打开R以导入,则所有这些都可以工作。但是,如果在之前测试导入后有R打开,它就会失败。如果没有关闭NetLogo,则导入失败。如果在从NetLogo导出时打开了R,则会追加导出文本,而不是替换文件。
有没有从NetLogo中强制释放该文件的方法?或者,是否有来自R的任何方式来覆盖NetLogo (关闭但未释放)文件的控制?
发布于 2016-01-13 15:24:43
我试着重复这个问题,但失败了。我在用
我还试着用R的read.csv来写和读CSV。我无法复制你所描述的问题。你有可能在这个程序之外的任何地方打开这个文件吗?您对上述任何一个版本有何不同之处?
我注意到的一件事是,当文件原语错误时,文件将被打开,这会导致上面的过程写入无效的gml文件。我建议在函数顶部调用file-close或file-close-all,就像使用file-delete一样。
https://stackoverflow.com/questions/34740065
复制相似问题