the same way that wartime radio operators understood code or a more apt example being telegraph line operators understanding what the magical tapping robot was saying
R2-D2's beeps actually do have tonal inflections and movements the same way Groot's do. When he's annoyed he speeds up the beeps and they become a higher pitch, when he feels empathy he will lean forward slightly and move his "head". It's like being able to communicate with someone that doesn't speak your language... you might not know exactly what they are saying, but for the most part, if they are being sincere you can pick up what they mean.
https://www.youtube.com/watch?v=9Rf-jB1XFO0