R-如何使用GML格式文件将Igraph Edge属性设置为字符串



i使用gml图形文件格式将图形读取到igraph(r版本)中。有没有办法将边缘属性设置为字符串?似乎有些属性标签被允许具有字符串值,而其他属性则没有。示例输入文件:

graph [
node [
    id 1
    control 1
    label "CiscoSW-1"
]
node [
    id 2
    control 1
    label "CiscoSW-z"
]
edge [
    source 1
    target 2
    difficulty 'A,B,C'
    label "CiscoSW-1"
]
]

似乎read_graph似乎不喜欢单引号' ',因此您需要将其交换为双引号" "

做到这一点的一种方法是在文件中阅读, gsub删除有问题的报价,然后用 read_graph再次读取它。因此,如果将图形文件保存为so.gml,则

# Read in file, `gsub` quotes and write to tempfile()
r <- gsub("[']", """, readLines("so.gml"))
cat(r, file=temp<-tempfile())
# Read amended gml file 
g <- read_graph(temp, format="gml")

检查边缘属性是预期的

edge.attributes(g)