df_ehr = data.frame(Patient = c(1, 1, 2, 1, 2, 1, 1, 3, 4),
Month = c(1, 1, 1, 2, 2, 3, 3, 4, 4),
Parent_Code = c('C1', 'C2', 'C2', 'C1', 'C1', 'C1',
'C2', 'C3', 'C4'),
Count = 1:9)
library(RSQLite)
test_db_path = tempfile()
test_db = dbConnect(SQLite(), test_db_path)
dbWriteTable(test_db, 'df_monthly', df_ehr, overwrite = TRUE)
dbDisconnect(test_db)
output_db_path = tempfile()
sql_cooc(test_db_path, output_db_path, autoindex = TRUE)
test_db = dbConnect(SQLite(), output_db_path)
spm_cooc = dbGetQuery(test_db, 'select * from df_monthly;')
dbDisconnect(test_db)
spm_cooc
Run the code above in your browser using DataLab