我有一个Filemaker Pro 12关系数据库,用于接受手术治疗的肺癌患者。由于一名患者可能在一次或多次手术中切除了一个或多个癌症等,因此患者特征/人口统计数据在一张表格(患者)中,他们手术的患者在另一张表格(治疗)中,患者ID和癌症特征在由PatientID确定的另一个表格(病理学)中,但是通过手术表的SurgeryID与癌症被去除相关联。无法使用SQL和ODBC连接将R数据帧保存到filemaker Pro数据库
我想将所有“内部加入”数据备份为一个平面文件,每个不同癌症的记录以及每位患者的每项手术(因此如果患者有多个癌症和/或操作)。
con = odbcConnect("LC", uid = "uid", pwd = "pwd")
PatSurg <-sqlQuery(con, paste("SELECT * FROM Patient P INNER JOIN Treatment T ON P.PatientID = T.PatientID"))
PatPath <-sqlQuery(con, paste("SELECT * FROM Patient P INNER JOIN Pathology H ON P.PatientID = H.PatientID"))
Full <- merge(PatSurg, PatPath, by = intersect(names(PatSurg), names(PatPath)))
View(Full)
这成功地创建的数据帧(全部)完全一样的平坦平面文件我想保存到一个空的现有的Filemaker:
我已经使用因此进口3个的Filemaker表病人,治疗,病理学Pro数据库与表胸相同的列名称。
我当时想我会尝试简单的指令:
sqlSave(con, Full, tablename = "Thoracic")
,并返回错误:
Error in sqlSave(con, Full, tablename = "Thoracic") : table ‘Thoracic’ already exists
气馁,我放弃了表名,并重新保存它:
sqlDrop(con, "Thoracic", errors = FALSE)
sqlSave(con, Full, tablename = "Thoracic")
其中返回了一个新的错误:
Error in sqlSave(con, Full, tablename = "Thoracic") : [RODBC] Failed exec in Update HY000 502 [FileMaker][FileMaker] (502): Field failed numeric value validation test
然后我想,也许我应该使用sqlQuery命令和INSERT,但不知道如何在SQL/ODBC表达式时引用我的R数据框。我想:
sqlQuery(con, "INSERT INTO Thoracic ", Full)
sqlQuery(con, "INSERT INTO Thoracic VALUES", Full)
两个返回:
Error in if (errors) return(odbcGetErrMsg(channel)) else return(invisible(stat)) : argument is not interpretable as logical In addition: Warning message: In if (errors) return(odbcGetErrMsg(channel)) else return(invisible(stat)) : the condition has length > 1 and only the first element will be used
sqlAppendTable(con, "Thoracic", Full)
返回:
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘sqlAppendTable’ for signature ‘"RODBC"’
sqlQuery(con, "INSERT INTO Thoracic VALUES Full")
返回:
[1] "42000 8310 [FileMaker][FileMaker] FQL0001/(1:29): There is an error in the syntax of the query." [2] "[RODBC] ERROR: Could not SQLExecDirect 'INSERT INTO Thoracic VALUES Full'"
我应该如何在SQL查询中引用我的R数据框“Full”。我所看到的所有问题都只涉及将数据从OBDC源导入数据框。这是最简单的一点!