R2-D2 was in on the scheme to keep the secret away from Luke and Leia. He was devoted to the Skywalker family, and at the guidance of Obi-wan and
Obi-Wan wanted to protect Luke
The news that his father was in fact a Jedi Knight who had died during the Clone Wars was a lot to take in itself, but still less severe than learning that your father had turned to the Dark Side, brought about the end of the Jedi Order and become the most feared man in the galaxy.
R2-D2 was present when Padmé gave birth to Leia and Luke, so he knew Luke was Anakin's son – but what he didn't know was that Anakin became Darth Vader. In addition to that, Anakin's fall was surely a painful event in R2-D2's life, one that he definitely wouldn't like to remember or even talk about.
Obi-Wan Kenobi
Obi-Wan infamously lied to Luke about his parentage, telling him that Darth Vader murdered Anakin Skywalker, which was metaphorically true but a manipulative move that Luke confronted him on in Return of the Jedi.
C-3PO had his memory wiped at the end of Revenge of the Sith. R2-D2 did not, but why he never told Luke the truth is actually quite simple. That ends up happening when you make the prequels after the originals lol. Bail Organa had Captain Antilles erase C-3PO's mind shortly after the twins were born.
Obi-Wan Was Pretending He Didn't Know R2-D2
The base assumption of why Obi-Wan doesn't remember R2-D2 -- in light of the prequels -- is that Obi-Wan is feigning ignorance in A New Hope to downplay the importance of the droid's arrival.
Darth Vader didn't learn he had a daughter until Return of the Jedi, when he stood before Emperor Palpatine. The Emperor's power probed Luke's mind, attempting to goad him to fall to the dark side, and he discovered Leia's existence. "Sister," the Emperor taunted.
Master Yoda knew that Darth Vader was once Anakin Skywalker- the boy he sensed too much fear in to train way back in Star Wars: The Phantom Menace. For many years it's been assumed Master Yoda was aware from the day Vader gained his cybernetic enhancements and signature wheeze.
Master Yoda has risen above all others to claim the top spot as the most powerful Jedi of all time and the true chosen one according to IGN's audience. He won pretty handily as well, as he was victorious in 89,756 of his 95,243 battles and had a win percentage of 94.2%.
As such, by the time of Anakin and Padme's marriage, Anakin was the owner of C3PO and Padme the owner of R2D2 (or the state of Naboo).
Yoda soon agrees to train Luke about the Force and how to be a Jedi. We believe this is the first meeting between all three. But in the “Star Wars” prequel trilogy, we learn R2D2 and Yoda ran in some of the same social circle. And now, a new book has confirmed that Yoda knew who R2D2 was in “Empire Strikes Back.”
The Emperor is Officially Anakin's 'Father'
And for those who might wonder how Anakin would actually be able to learn such an Earth-shattering truth, without suspicion of it being further manipulation by his Sith Master, the circumstances of the story help explain.
Kylo Ren was always obsessed with his grandfather. He didn't learn he was the grandson of Darth Vader until he was a teenager, when a recording from Bail Organa - intended to be a private message for Leia - was shared with the entire galaxy.
Lucas has said that he knew Vader was Luke's father while writing the first film, though the relationship is not explicitly evidenced before said draft of The Empire Strikes Back. The new plot element of Luke's parentage had drastic effects on the series.
Of course, the Father almost immediately wiped Anakin's memory, because he couldn't very well achieve balance knowing what he knew of his future. That's very interesting, though. It means that the Father knew that Anakin will become Vader, will destroy the Jedi, will literally annihilate whole worlds….
Padmé was well aware that Anakin had committed dark crimes that would've started his fall to the dark side. He even confessed to her that he had massacred an entire Tusken Raider village to avenge his mother, leaving no one alive.
Despite seeing Vader as an idol, Kylo conveniently ignored his grandfather's redemption. He was well aware of what happened, and it's likely Luke himself who told Ben about the events of Star Wars: Return of the Jedi.
She had two conversations with Obi-wan about Anakin (before and after Mustafar) but we don't if he told her Anakin was now called Darth Vader. If you are asking about Vader post-Mustafar, then no, she doesn't.
What would happen if Darth Vader came across R2-D2 and C3PO? He came across Threepio on Bespin. He either didn't realize it was the same protocol droid or figured he'd been memory-wiped so FUNCTIONALLY wasn't the same droid and didn't care.
Some people believed it was Breha who Leia was remembering on Endor, thinking she was her biological mother. However, this didn't end up being true as the prequels established Padmé as her (and Luke's) mother.
Obviously, C-3PO does not recognize Vader because his memory was wiped at the end of Revenge of the Sith.
Every time she speaks, he remembers Padmé. Fighting alongside Sabé reminds him of fighting alongside his wife. While that is certainly painful enough, it's also reminds Vader of the man he used to be, a past he had long ago attempted to kill and bury. However, the memory of Padmé via Sabé won't let his past stay there.
In The Phantom Menace, set 32 years before A New Hope, R2-D2 is portrayed as belonging to the Naboo defense forces, one of three astromech droids deployed for repair duty onboard Queen Padmé Amidala's (Natalie Portman) starship as it attempts to get past the Trade Federation blockade.