bad_weak_ptr error knitting rmarkdown

Hello, I got an error upon knitting, that can only be removed by removing all caches and re knitting. However, I am not sure how to reproduce this bug, so I have not included a self-contained and reproducible example.

The code is only to plot a ggplot object.

The error is as follows:

Error:
! bad_weak_ptr
Backtrace:
  1. ... %>% setNames(names(annotation_all_pc))
  4. base::lapply(...)
  5. FUN(X[[i]], ...)
  6. global add_introns_to_gr(annotation_all_pc[[x]], txdb[[x]])
 10. GenomicFeatures::intronsByTranscript(txdb, use.names = T)
     ...
 20. DBI::dbListTables(conn)
 21. RSQLite:::sqliteListTables(conn)
 23. RSQLite::dbSendQuery(conn, sql)
 24. RSQLite (local) .local(conn, statement, ...)
 28. RSQLite:::result_create(conn@ptr, statement)
Execution halted

The session info

R version 4.3.0 (2023-04-21)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Debian GNU/Linux 12 (bookworm), RStudio 2023.3.1.446


Locale:
  LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8   
  LC_MESSAGES=en_US.UTF-8    LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C            
  LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

time zone: Etc/UTC
tzcode source: system (glibc)

Package version:
  base64enc_0.1.3   bslib_0.4.2       cachem_1.0.8      cli_3.6.1         digest_0.6.31     ellipsis_0.3.2    evaluate_0.21     fastmap_1.1.1    
  fontawesome_0.5.1 fs_1.6.2          glue_1.6.2        graphics_4.3.0    grDevices_4.3.0   highr_0.10        htmltools_0.5.5   jquerylib_0.1.4  
  jsonlite_1.8.4    knitr_1.43        lifecycle_1.0.3   magrittr_2.0.3    memoise_2.0.1     methods_4.3.0     mime_0.12         R6_2.5.1         
  rappdirs_0.3.3    rlang_1.1.1       rmarkdown_2.21    sass_0.4.6        stats_4.3.0       stringi_1.7.12    stringr_1.5.0     tinytex_0.45     
  tools_4.3.0       utils_4.3.0       vctrs_0.6.2       xfun_0.39         yaml_2.3.7       

Pandoc version: 2.19.2

This error seems like something related to database when I search on Github : Code search results ยท GitHub

So I don't think this is R Markdown or Knitr related, and the issue should also happen with R console. You should check your DB calls

Thanks for the reply!

The thing is, the issue does not happen when I just run it on the console without knitting, which is why I thought the problem might be related with Knitr/rmarkdown...

Interesting...

Can you share content of the document ? What is the chunk that gets the error ? Are you calling DB directly ?

Does it error the same if you call rmarkdown::render() ? In case you were clicking on Render in IDE.

Hi,

I also realized that the chunk does not run if I set cache.lazy=FALSE as "long vectors are not supported yet"

I'm not sure what means by calling DB. In this case I used TxDb objects of the GenomicFeatures package, which might be the DB causing the problem?

The code is quite long and messy but here it is.

add_introns_to_gr <- function(gr, txdb){

  gr_ids <- gr$transcript_id %>% unique() %>% na.omit()

  introns <- intronsByTranscript(txdb, use.names = T) %>% unlist()
  introns <- introns[names(introns) %in% gr_ids]

  introns$type <- "intron"
  introns$transcript_id <- names(introns)

  c(gr, introns)
}

add_intergenic_to_gr <- function(gr){
  intergenic_gaps <- gr %>% gaps() %>% mutate(type = "intergenic")

  c(gr, intergenic_gaps)
}

annotation_all_pc <-  lapply(annotation_all_pc, add_intergenic_to_gr)

annotation_all_pc <- names(annotation_all_pc) %>% lapply(function(x){
  add_introns_to_gr(annotation_all_pc[[x]], txdb[[x]])
}) %>% setNames(names(annotation_all_pc))


annotation_all_pc_df <- annotation_all_pc %>%
  lapply(function(x){x %>% as_tibble %>% select(1:type)}) %>%
  bind_rows(.id = "species") %>%
  mutate(species = case_when(species %in% c("oki", "osa", "bar") ~ paste0("odioica_", species), T ~ species)) %>% 
  left_join(species_name_table)

Can you help me with this ? Does the error happens in RStudio IDE only ? or also in R console with rmarkdown::render() directly ?

Are you caching the chunk using cache = TRUE ? What is your cached chunk in this case ?

Usually this message means that you should set cache.lazy = FALSE to avoid lazy loading.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.