library(dplyr)

Dangerous

Things that fail without immediate warning

For in loop

My favorite loop pattern leads to bogus numbers:

for (i in bit64::as.integer64(1:3))
  print(i)

Any apply

sapply, lapply, mapply, etc. lead to bogus numbers:

sapply(bit64::as.integer64(1:3), print)

Should use purrr::map instead:

purrr::map(bit64::as.integer64(1:3), print)

The %in% operator when other variable is not integer64

as.numeric(1) %in% bit64::as.integer64(1:3)
as.integer(1) %in% bit64::as.integer64(1:3)
bit64::as.integer64(1) %in% as.numeric(1:3)
bit64::as.integer64(1) %in% as.integer(1:3)

RJSONSIO::toJson

Converts to bogus numbers:

RJSONIO::toJSON(list(i = bit64::as.integer64(1)))

Annoying

Things that throw an error, but can be avoided by explicit casting.

Must explictly cast when reading from CSV

file <- tempfile()
df <- data.frame(i = bit64::as.integer64(1))
readr::write_csv(df, file)

df2 <- readr::read_csv(file, col_types = c(i = "c")) %>%
    mutate(i = bit64::as.integer64(.data$i))
df2

Bind_rows cannot combine integer64 with numeric

# This throws and error:
bind_rows(data.frame(i = bit64::as.integer64(1)),
          data.frame(i = as.numeric(2)))

RSQLite (and Andromeda) only knows 64-bit integers

For this reason, the type of integer that is returned depends on the value:

df <- data.frame(key = c(1,2),
                 value = bit64::as.integer64(c(2^2, 2^62)))
andr <- Andromeda::andromeda(table = df)
andr$table %>%
  filter(key == 1)

andr$table %>%
  filter(key == 2)


OHDSI/Hades documentation built on April 3, 2025, 3:06 p.m.