The question Why does R2-D2 try to electrocute Yoda? presuposses that such an attempt at electrocution occurred, something that I don't recall ever even happening in The Empire Strikes Back in the first place. When exactly does R2 try to attack or shock Yoda?
Or at least he doesn't in the film.
Here's a complete transcript of the scene from Empire:
"With the aid of a walking stick, the tiny stranger moves over to one of the cases of supplies. He begins to rummage around.
Artoo moves to the edge of the case - standing almost eye level to the creature who is carelessly handling the supplies - and squeaks his disapproval.
Their tiny visitor pick up the container of food Luke was eating from and takes a bite.
LUKE Put that down. Hey! That's my dinner!
The creature spits out the bite he has taken. He makes a face.
CREATURE How you get so big, eating food of this kind?
He flips the container in Luke's direction and reaches into one of Luke's supply cases.
LUKE Listen, friend, we didn't mean to land in that puddle, and if we could get our ship out, we would, but we can't, so why don't you just... CREATURE (teasing) Aww, cannot get your ship out?
The creature spots something of interest in Luke's case. Luke loses patience and grabs the case away. The creature retains his prize - a tiny power lamp - and examines it with delight.
LUKE Hey, you could have broken this. Don't do that. Ohhh... you're making a mess. Hey, give me that! CREATURE (retreating with the lamp) Mine! Or I will help you not.
Clutching its treasure, the creature backs away from Luke, drawing closer to Artoo. As Luke and the creature argue, one of Artoo's little arms slowly moves out toward the power lamp, completely unnoticed by the creature.
LUKE I don't want your help. I want my lamp back. I'll need it to get out of this slimy mudhole. CREATURE Mudhole? Slimy? My home this is.
Artoo grabs hold of the lamp and the two little figures are immediately engaged in a tug-of-war over it.
Artoo beeps a few angry, "Give me thats."
CREATURE Ah, ah, ah! LUKE Oh, Artoo, let him have it! CREATURE Mine! Mine! LUKE Artoo! CREATURE Mine!
The creature lets go with one hand and pokes Artoo lightly with one finger. Artoo reacts with a startled squeal, and lets go.
CREATURE Mine! LUKE (fed up) Now will you move along, little fella? We're got a lot of work to do. CREATURE No! No, no! Stay and help you, I will. (laughs) Find your friend, hmm? LUKE I'm not looking for a friend. I'm looking for a Jedi Master. CREATURE Oohhh. Jedi Master. Yoda. You seek Yoda. LUKE You know him? CREATURE Mmm. Take you to him, I will. (laughs) Yes, yes. But now, we must eat. Come. Good food. Come.
With that, the creature scurries out of the clearing, laughing merrily.
Luke stares after him. All he sees is the faint light from the small power lamp moving through the fog. Luke makes his decision and starts after the creature.
CREATURE (in the distance) Come, come.
Artoo, very upset, whistles a blue streak of protest.
LUKE Stay here and watch after the camp, Artoo."
No electrocution occurs. Perhaps that asker was conflating this scene with the one where R2 himself is shocked, later in the film.