OHDSI / ROhdsiWebApi

An R package for interfacing with a WebAPI instance
https://ohdsi.github.io/ROhdsiWebApi
10 stars 17 forks source link

Error in convertConceptSetDefinitionToTable when concept set is empty #149

Closed ablack3 closed 3 years ago

ablack3 commented 4 years ago

library(ROhdsiWebApi)
baseUrl <- 'http://api.ohdsi.org:80/WebAPI'

meta <- getConceptSetDefinitionsMetaData(baseUrl)

head(meta, 3)
#> # A tibble: 3 x 6
#>   createdBy modifiedBy createdDate         modifiedDate             id name     
#>   <chr>     <chr>      <dttm>              <dttm>                <int> <chr>    
#> 1 ""        ""         2019-06-28 22:52:04 2019-06-28 22:52:04 1799700 diabetes 
#> 2 ""        ""         2019-06-29 01:32:03 2019-06-29 01:32:03 1799713 XD_Myoca~
#> 3 ""        ""         NA                  NA                      936 Thoracic~

# this code gives an error
conceptSetDefinition1 <- getConceptSetDefinition(conceptSetId = 1799700, 
                                                 baseUrl = baseUrl)
convertConceptSetDefinitionToTable(conceptSetDefinition1)
#> Error in UseMethod("tbl_vars"): no applicable method for 'tbl_vars' applied to an object of class "list"

# However these examples work fine
conceptSetDefinition2 <- getConceptSetDefinition(conceptSetId = 1799713, 
                                                 baseUrl = baseUrl)
convertConceptSetDefinitionToTable(conceptSetDefinition2)
#> # A tibble: 1 x 13
#>   isExcluded includeDescenda~ includeMapped conceptId conceptName
#>   <lgl>      <lgl>            <lgl>             <int> <chr>      
#> 1 FALSE      TRUE             FALSE           4329847 Myocardial~
#> # ... with 8 more variables: standardConcept <chr>,
#> #   standardConceptCaption <chr>, invalidReason <chr>,
#> #   invalidReasonCaption <chr>, conceptCode <chr>, domainId <chr>,
#> #   vocabularyId <chr>, conceptClassId <chr>

conceptSetDefinition3 <- getConceptSetDefinition(conceptSetId = 936, 
                                                 baseUrl = baseUrl)
convertConceptSetDefinitionToTable(conceptSetDefinition3)
#> # A tibble: 16 x 13
#>    isExcluded includeDescenda~ includeMapped conceptId conceptName
#>    <lgl>      <lgl>            <lgl>             <int> <chr>      
#>  1 FALSE      FALSE            FALSE          44832392 Aortic ane~
#>  2 FALSE      FALSE            FALSE          44837117 Aortic ane~
#>  3 FALSE      FALSE            FALSE          45766211 Aortic val~
#>  4 FALSE      FALSE            FALSE           4177225 Chronic di~
#>  5 FALSE      FALSE            FALSE           4137219 Chronic no~
#>  6 FALSE      FALSE            FALSE          44819720 Dissecting~
#>  7 FALSE      FALSE            FALSE          40480639 Dissecting~
#>  8 FALSE      FALSE            FALSE            320739 Dissection~
#>  9 FALSE      FALSE            FALSE          44824258 Dissection~
#> 10 FALSE      FALSE            FALSE          44824259 Dissection~
#> 11 FALSE      FALSE            FALSE          44820878 Dissection~
#> 12 FALSE      FALSE            FALSE            436136 Dissection~
#> 13 FALSE      FALSE            FALSE            312343 Ruptured a~
#> 14 FALSE      FALSE            FALSE           4173464 Rupture of~
#> 15 FALSE      FALSE            FALSE            441875 Thoracic a~
#> 16 FALSE      FALSE            FALSE            433222 Thoracoabd~
#> # ... with 8 more variables: standardConcept <chr>,
#> #   standardConceptCaption <chr>, invalidReason <chr>,
#> #   invalidReasonCaption <chr>, conceptCode <chr>, domainId <chr>,
#> #   vocabularyId <chr>, conceptClassId <chr>

# I think the reason is that the first concept set is empty
str(conceptSetDefinition1, max.level = 2)
#> List of 7
#>  $ createdBy   : chr ""
#>  $ modifiedBy  : chr ""
#>  $ createdDate : num 1.56e+12
#>  $ modifiedDate: num 1.56e+12
#>  $ id          : int 1799700
#>  $ name        : chr "diabetes"
#>  $ expression  :List of 1
#>   ..$ items: list()
str(conceptSetDefinition2, max.level = 2)
#> List of 7
#>  $ createdBy   : chr ""
#>  $ modifiedBy  : chr ""
#>  $ createdDate : num 1.56e+12
#>  $ modifiedDate: num 1.56e+12
#>  $ id          : int 1799713
#>  $ name        : chr "XD_Myocardial Infarction"
#>  $ expression  :List of 1
#>   ..$ items:List of 1
str(conceptSetDefinition3, max.level = 2)
#> List of 7
#>  $ createdBy   : chr ""
#>  $ modifiedBy  : chr ""
#>  $ createdDate : NULL
#>  $ modifiedDate: NULL
#>  $ id          : int 936
#>  $ name        : chr "Thoracic Aortic Dissection"
#>  $ expression  :List of 1
#>   ..$ items:List of 16

Created on 2020-07-14 by the reprex package (v0.3.0)

How about returning a dataframe with zero rows if the concept set is empty?

gowthamrao commented 3 years ago

@ablack3 can you please confirm if this is still an issue

siirtola commented 3 years ago

I believe this is still a problem – an empty concept set crashes convertConceptSetDefinitionToTable with quite an esoteric error message:

Error in UseMethod("tbl_vars") : 
  no applicable method for 'tbl_vars' applied to an object of class "NULL"