In Rogue One we see R2-D2 and C3P0 in the Rebel base on Yavin 4. While Rogue One is on their mission at the end of the movie, R2-D2 and C3P0 see the X-Wings leave the rebel base and the droids make a funny comment, but don’t appear to be loading up to leave as well.
I seem to also remember a comment by one of the Rebel leaders that the Admiral had already gathered the fleet and was heading out.
And the next we see of R2-D2 and C3P0 seems to be shortly after the ending of Rogue One, aboard Leia’s ship (Tantive IV) with R2-D2 receiving the stolen Death Star plans at the start of Episode IV.
So when did R2-D2 and C3P0 manage to get aboard Leia’s ship?