2017-03-08 35 views
0

我正在嘗試使用RNeo4j包創建R中的圖形數據庫。基本上@Nicloe White已經顯示here是我想要完全通過RStudio IDE實現的。我已將data讀入R,並使用lubridate包對日期字段進行了一些基本的管理。此後,我遵循Nicole爲hflights數據集顯示here的內容。這是相關代碼:在RNeo4j中使用`appendCypher()`時出錯

query=" 
CREATE (complaint:Complaint {id: TOINT({ComplaintID})}) 
SET complaint.day = ({ComplaintDay}), 
    complaint.month = ({ComplaintMonth}), 
    complaint.year = ({ComplaintYear}) 
MERGE (company:Company {name:{CompanyName}}) 
MERGE (response:Response {name:{Companyresponsetoconsumer}}) 

CREATE (complaint) -[:AGAINST]-> (company) 
CREATE (response) -[r:TO]-> (complaint) 

SET r.timely = CASE {Timelyresponse} WHEN 'Yes' THEN true ELSE false END, 
    r.disputed = CASE {Consumerdisputed} WHEN 'Yes' THEN true ELSE false END 


" 

tx = newTransaction(graph) 

for(i in 1:nrow(complaint)) { 
    row = complaint[i, ] 
    appendCypher(tx, query, 
       ComplaintID=complaint$Complaint.ID, 
       ComplaintDay=complaint$Complaint.Day, 
       ComplaintMonth=complaint$Complaint.Month, 
       ComplaintYear=complaint$Complaint.Year, 
       CompanyName=complaint$Company, 
       Companyresponsetoconsumer=complaint$Company.response.to.consumer, 
       Timelyresponse=complaint$Timely.response., 
       Consumerdisputed=complaint$Consumer.disputed.) 
} 
commit(tx) 

summary(graph) 

然而,當我運行for循環,我得到以下錯誤:

Error in appendCypher.transaction(tx, query, ComplaintID = 

complaint$Complaint.ID, : 
    Neo.ClientError.Statement.TypeError 
Expected a String or Number, got: List(1913026, 99413, 1420666, 1139505, 850511, 211452, 299293, 967118, 1342525, 218870, 936088, 1577433, 396460, 976892, 1713179, 985796, 1274906, 1524883, 549683, 375379, 2083877, 1804301, 568928, 643695, 2013448, 1822596, 1054868, 1058533, 1972148, 1053127, 1546919, 1974786, 1386150, 558306, 2029982, 1812827, 2112000, 1279031, 1729024, 811685, 423229, 211371, 550247, 1837165, 589977, 363963, 773706, 1422738, 362615, 1918434, 31932, 101419, 109634, 799711, 568707, 425802, 1354727, 905367, 433560, 950090, 1615178, 1085081, 1842311, 55218, 82206, 8990, 1716274, 1199075, 315208, 976080, 1747751, 1424814, 757803, 61250, 592018, 974917, 2046258, 1901776, 123518, 1362552, 257123, 1212622, 1663172, 1200587, 84365, 358901, 1920239, 691273, 226122, 36142, 1615314, 809300, 1987176, 596079, 1619346, 1261257, 984128, 793228, 173250, 249440, 192131, 1759419, 1394747, 1316550, 1890080, 862502, 1192961, 506058, 2000389, 

的狀態代碼表示,也許complaint$Complaint.ID類型不被支持。但是TOINT不會照顧這個嗎?

請希望得到一些幫助。

+0

你逝去的名單ComplaintID,並期待一個字符串或數 –

+0

'STR(投訴$ Complaint.ID)'顯示,它是一個整數。 – Dhiraj

回答

0

for循環中的一個非常愚蠢的錯誤。這是什麼在起作用:

for(i in 1:nrow(complaint)) { 
    row = complaint[i, ] 
    appendCypher(tx, query, 
       ComplaintID=row$Complaint.ID, 
       ComplaintDay=row$Complaint.Day, 
       ComplaintMonth=row$Complaint.Month, 
       ComplaintYear=row$Complaint.Year, 
       CompanyName=row$Company, 
       Companyresponsetoconsumer=row$Company.response.to.consumer, 
       Timelyresponse=row$Timely.response., 
       Consumerdisputed=row$Consumer.disputed.) 
}