The two droids knew very well Darth Vader was Anakin Skywalker. R2 doesn't know it. It's as simple as that. He isn't present on Mustafar (he flies with Anakin but is ordered to stay at the ship.
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.
C-3P0's memory was wiped at the end of Episode III so if he wasn't told he had no idea that his maker was the future Darth Vader. R2-D2 remembers it all and if I had to guess he is quiet sad about Anakin's turn to the dark side.
During the Clone Wars, it was common practice to wipe the minds of astromech droids after every mission to avoid the risk of Separatists taking valued information. But Anakin remained staunchly against this idea for R2-D2, meaning the droid never had to worry about losing the memories of his past.
Obviously, C-3PO does not recognize Vader because his memory was wiped at the end of Revenge of the Sith.
Revenge of the Sith
After Anakin falls to the dark side of the Force and becomes Darth Vader, he takes R2-D2 with him when he goes to assassinate the Separatist council, but tells him to stay with the ship.
Both R2D2 and C3PO both know that Darth Vader and Anakin are one and the same. 3PO's memory was erased back in Star Wars Episode III: Revenge of the Sith but was restored by R2 back in Star Wars Episode IV: The Rise of Skywalker. As such, they both remember everything that happened.
Such cycles of fate no longer surprised the nine-hundred-year-old Jedi. So there you have it. Yoda and R2D2 knew each other and the galaxy is even a smaller world than we think.
C-3PO, his robot companion, could speak 6-million languages including excellent English with a hint of a British accent and all R2-D2 could muster were beeps and whistles. Clearly the technology was there to let him speak, but whoever designed him intentionally decided to stick with the beeps and whistles.
That meant studiously avoiding the old Jedi's perceived inability to recognize R2-D2, who, with the prequels and The Clone Wars animated series in place, became one of Obi-Wan's most stalwart companions before their renewed acquaintance on Tatooine.
R2 doesn't know it. It's as simple as that. He isn't present on Mustafar (he flies with Anakin but is ordered to stay at the ship. He isn't present while the slaughtering of the seperatists or the fight of Anakin/Obi-Wan.), differently to Obi-Wan and C-3PO.
In fact, R2 didn't witness Anakin and Obi-Wan's duel, but he returned to the ship and left the place with the latter, presumably with the knowledge that his former master isn't alive anymore. So, essentially, the droid had no idea that Darth Vader is, in fact, Anakin Skywalker.
C-3PO accidentally became part of the Battle of Geonosis when his head was affixed on top of a battle droid's body after a mishap in the Geonosian droid factory. R2-D2 and C-3PO witnessed the secret wedding between Anakin Skywalker and Padmé Amidala on Naboo.
R2-KT was a 1.09 meter-tall, feminine R2 series astromech droid produced by Industrial Automaton.
As such, R2D2 appears to be the state property of Naboo. Queen Amidala as the head of state exercised her control over R2D2. The Droid continued his service to Amidala while she was a Senator.
R2-D2 was most definitely male. He is constantly referred to as "he" by the characters in the films, both human and droid characters (such as C-3PO).
R2-D2, the indomitable droid and mainstay of the Star Wars series, may be responsible for one more incredible feat: saving Grogu.
Other Characters That Can Understand Droids In Star Wars
Obi-Wan Kenobi was another human who could speak Binary, as well as Anakin, who shared the strongest relationship with R2-D2, as seen in the prequel trilogy and Star Wars: The Clone Wars.
Canon characters, such as Anakin Skywalker, whose relationship with R2-D2 is one of the best in the whole series, Rey, Poe Dameron, Hera Snydulla and Kazuda Xiono are fluent in the droid language. And after spending decades with R2 himself, Luke Skywalker is also able to understand him.
The Clone Wars series are considered canonical and, perhaps more importantly, had personal input and approval by George Lucas. On them, we learn that R2D2 was Anakin's personal droid during the war, and a droid had he trusted so much he wouldn't even wipe the memory, something he was admonished by Obi-Wan for.
“It's good to fly with you again, my old friend,” the old man said, so softly Han wasn't sure he had heard him right. C-3P0 didn't; his memory was wiped at the end of Revenge of the Sith to prevent him from spilling the beans.
Unlike C-3PO, little about R2-D2's previous life is known. In old Star Wars canon, he was purchased by the Royal Engineers of Naboo, who made after-market additions to the droid before shipping him out into space.
However, Leia's strong-mindedness during Vader's probe denied him the opportunity to discover she was his daughter. That serves to justify Vader's lack of awareness of his connection to Leia, although, perhaps, not as satisfyingly as if Lucas had planned for the relationship from the beginning.
Vader relies on the complex life support system of his suit to survive and it happens to be very vulnerable to electrical discharges. So, if Vader ever had unleashed Force lightning, there's a good chance it would've caused his suit to short circuit, thus, killing him.