cannot allocate vector of size

R asked the OS for one contiguous block it could not get

why

R needs a single contiguous allocation for a vector or matrix, so this can fail while plenty of RAM appears free. Copy-on-modify makes it worse: an innocuous-looking operation on a large object can transiently need twice its size.

what to do

Work on a subset first to confirm the logic, then reduce peak memory rather than just asking for more: drop objects you no longer need with rm() plus gc(), avoid growing objects in loops, and use sparse or on-disk representations (Matrix, DelayedArray, HDF5) for single-cell-scale data.

R memory model
This is one entry from BioErrors, a catalogue of bioinformatics error messages that point at the wrong thing. Every entry was traced to its real cause before it was written down.
If your error is not in it, paste it there and it gets traced and added.