Collect a tbl object and convert integer64 columns to double

Description

If you connect to the All of Us database via aou_connect(), integer columns will be converted to the int64 class, which can represent 64-bit integers. This is safer than keeping as R’s default integer class, because some of the values of the ID columns in All of Us are larger than R can handle as integers. However, this can make working with the local table more difficult in RStudio as a vector of values will not match the int64 class. This is not a problem in Jupyter notebooks, meaning that code that works on one platform may not work on another. A safe practice is to use aou_collect(), which works just like dplyr::collect() except that any integer values are converted to doubles. If this is not what you want, set convert_int64 = FALSE.

Usage

aou_collect(data, convert_int64 = TRUE, ...)

Arguments

data A reference to a remote database table (or unexecuted query)
convert_int64 Do you want to convert integer values to doubles? Defaults to TRUE
Other arguments passed to dplyr::collect()

Details

[Experimental]

Value

a local dataframe

Examples

library("allofus")


# connect to database
con <- aou_connect()

# returns 2 rows, as expected
dplyr::tbl(con, "concept") %>%
  dplyr::filter(concept_id %in% c(1112807, 4167538)) %>%
  aou_collect() %>%
  dplyr::filter(concept_id %in% c(1112807, 4167538))
# A tibble: 2 × 10
  concept_id concept_name     domain_id   vocabulary_id concept_class_id
       <dbl> <chr>            <chr>       <chr>         <chr>           
1    4167538 Contains aspirin Observation SNOMED        Qualifier Value 
2    1112807 aspirin          Drug        RxNorm        Ingredient      
# ℹ 5 more variables: standard_concept <chr>, concept_code <chr>,
#   valid_start_date <date>, valid_end_date <date>, invalid_reason <chr>
default_collect <- dplyr::tbl(con, "concept") %>%
  dplyr::filter(concept_id %in% c(1112807, 4167538)) %>%
  dplyr::collect()
# returns 2 rows in Jupyter and 0 in RStudio
dplyr::filter(default_collect, concept_id %in% c(1112807, 4167538))
# A tibble: 2 × 10
  concept_id concept_name     domain_id   vocabulary_id concept_class_id
     <int64> <chr>            <chr>       <chr>         <chr>           
1    4167538 Contains aspirin Observation SNOMED        Qualifier Value 
2    1112807 aspirin          Drug        RxNorm        Ingredient      
# ℹ 5 more variables: standard_concept <chr>, concept_code <chr>,
#   valid_start_date <date>, valid_end_date <date>, invalid_reason <chr>