R API and executeSQL | Ben Bimber | 2010-03-10 09:59 | |||||||||||||||||||||||||||||||||||||||||
Status: Closed | |||||||||||||||||||||||||||||||||||||||||||
I am trying to query lk from an R script and am receiving an error from the results. below is the R code: ------ library(Rlabkey) pedigree <- labkey.executeSql( baseUrl="http://localhost:8080/labkey", folderPath="/WNPRC/EHR", schemaName="study", sql = "select p.sex, p.id FROM study.pedigree p ", #showHidden = FALSE ) #pedigree.sire, pedigree; ---- when i run this query and try to select both columns in my SQL statement, I get this error: > pedigree <- labkey.executeSql( + baseUrl="http://localhost:8080/labkey", + folderPath="/WNPRC/EHR", + schemaName="study", + sql = "select p.sex, p.id FROM study.pedigree p ", + #showHidden = FALSE + ) Error in names(hold.dat) <- names(decode$rows[[1]]) : 'names' attribute [3] must be the same length as the vector [1] Calls: labkey.executeSql -> makeDF Execution halted When I try to run this query to return only the ID column, it works and returns this: > #pedigree.sire, > pedigree; Id 1 rhaa35 2 rhae81 3 rham30 4 rhao45 5 rhau10 6 rhau34 7 rhan92 8 rh-z19 ..... The output is normal. However, when I try to return p.sex (which is a lookup), I get a list for each record: + sql = "select p.sex FROM study.pedigree p ", + #showHidden = FALSE + ) > #pedigree.sire, > pedigree; Sex 1 list("NA") 2 list("NA") 3 list("NA") 4 list("NA") 5 list("f", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=f") 6 list("f", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=f") 7 list("f", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=f") 8 list("f", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=f") 9 list("f", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=f") 10 list("m", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=m") 11 list("f", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=f") 12 list("m", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=m") 13 list("m", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=m") 14 list("m", "/labkey/list/WNPRC/EHR/details.view?listId=24&pk=m") I'm assuming this has something to do with the fact that this field is a lookup. i should point out that study.pedigree is a query, not a dataset. Here is the SQL: SELECT d.id, d.dam, d.sire, --TODO: handle sex better CASE d.sex WHEN 'm' THEN 1 WHEN 'f' THEN 2 WHEN 'e' THEN 1 WHEN 'c' THEN 2 WHEN 'v' THEN 1 END AS sex, FROM study.demographics d Does anyone have a thought why the first executeSQL() would not be able to produce a dataframe? Do I need to edit the metadata of my query? Thanks in advance. |
|||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||