[Bioc-devel] Strange "internal logical NA value has been modified" error

Martin Morgan mtmorg@n@b|oc @end|ng |rom gm@||@com
Wed Oct 13 01:54:04 CEST 2021

It is from base R


and likely indicates memory corruption, not necessarily in the code that triggers the error (this is when the garbage collector is triggered...). Probably in *your* C code :) since it's the least tested. Probably writing out of bounds.

This could be quite tricky to debug. I'd try to get something close to a minimal reproducible example. 

I'd try to take devtools out of the picture, maybe running the test/testhat.R script from the command line using Rscript, or worst case creating a shell package that adds minimal code and can be checked with R CMD build --no-build-vignettes / R CMD check.

You could try inserting gc() before / after the unit test; it might make it clear that the unit test isn't the problem. You could also try gctorture(TRUE); this will make your code run extremely painfully slowly, which puts a big premium on having a minimal reproducible example; you could put this near the code chunks that are causing problems.

You might have success running under valgrind, something like R -d valgrind -f minimal_script.R.

Hope those suggestions help!


On 10/12/21, 6:43 PM, "Bioc-devel on behalf of Pariksheet Nanda" <bioc-devel-bounces using r-project.org on behalf of pariksheet.nanda using uconn.edu> wrote:

    Hi folks,

    I've been told to ask some of my more fun questions on this mailing list 
    instead of Slack.  I'm climbing the ladder of submitting my first 
    Bioconductor package (https://gitlab.com/coregenomics/tsshmm) and feel 
    like there are gremlins that keep adding rungs to the top of the ladder. 
      The latest head scratcher from running devtools::check() is a unit 
    test for a  trivial 2 line function failing with this gem of an error:

     > test_check("tsshmm")
    ══ Failed tests 
    ── Error (test-tss.R:11:5): replace_unstranded splits unstranded into + 
    and - ──
    Error in `tryCatchOne(expr, names, parentenv, handlers[[1L]])`: internal 
    logical NA value has been modified
       1. ├─testthat::expect_equal(...) test-tss.R:11:4
       2. │ └─testthat::quasi_label(enquo(expected), expected.label, arg = 
       3. │   └─rlang::eval_bare(expr, quo_get_env(quo))
       4. └─GenomicRanges::GRanges(c("chr:100:+", "chr:100:-"))
       5.   └─methods::as(seqnames, "GRanges")
       6.     └─GenomicRanges:::asMethod(object)
       7.       └─GenomicRanges::GRanges(ans_seqnames, ans_ranges, ans_strand)
       8.         └─GenomicRanges:::new_GRanges(...)
       9.           └─S4Vectors:::normarg_mcols(mcols, Class, ans_len)
      10.             └─S4Vectors::make_zero_col_DFrame(x_len)
      11.               └─S4Vectors::new2("DFrame", nrows = nrow, check = FALSE)
      12.                 └─methods::new(...)
      13.                   ├─methods::initialize(value, ...)
      14.                   └─methods::initialize(value, ...)
      15.                     └─methods::validObject(.Object)
      16.                       └─base::try(...)
      17.                         └─base::tryCatch(...)
      18.                           └─base:::tryCatchList(expr, classes, 
    parentenv, handlers)
      19.                             └─base:::tryCatchOne(expr, names, 
    parentenv, handlers[[1L]])
    [ FAIL 1 | WARN 0 | SKIP 0 | PASS 109 ]

    The full continuous integration log is here:

    The function in question is:

    replace_unstranded <- function (gr) {
         idx <- strand(gr) == "*"
         if (length(idx) == 0L)
             gr[! idx],
             `strand<-`(gr[idx], value = "+"),
             `strand<-`(gr[idx], value = "-")))

    Also online here:

    ... and the unit test is:

    test_that("replace_unstranded splits unstranded into + and -", {
                      GRanges(c("chr:100:+", "chr:100:-")))
         expect_equal(replace_unstranded(GRanges(c("chr:100", "chr:200:+"))),
                      sort(GRanges(c("chr:100:+", "chr:100:-", "chr:200:+"))))

    Also online here:

    What's interesting is this is *not* reproducible by running 
    devtools::test() but only devtools::check() so as far as I know there 
    isn't a way to interactively debug this while devtools::check() is going on?

    Every few days I've seen on that "internal ... value has been modified" 
    which prevents me from running nearly any R commands.  Originally I 
    would restart R, but then I found I could clear that error by running 
    gc().  No idea what causes it.  Maybe some S4 magic?

    Yes, I have downloaded the mailing lists for bioc-devel, r-devel, 
    r-help, and r-package-devel and see no mention of "value has been 
    modified" [1].

    Any help appreciated.


    [1] Mailing lists downloader:
    #!/bin/bash -x

    for url in 
         dir=$(basename $url)
         wget \
    	--timestamping \
    	--no-remove-listing \
    	--recursive \
    	--level 1 \
    	--no-directories \
    	--no-host-directories \
    	--cut-dirs 2 \
    	--directory-prefix "$dir" \
    	--accept '*.txt.gz' \
    	--relative \
    	--no-parent \

    Bioc-devel using r-project.org mailing list

More information about the Bioc-devel mailing list