ARP resolves a layer-3 address to a layer-2 address when a device sends something to another device. Because it is trying to resolve a layer-2 address, it only operates on the layer-2 LAN, not across a layer-3 device, e.g. router.
If R doesn't have an entry in its ARP table for 02, R will send an ARP request for the layer-2 address of 02, and the ARP tables of both devices will be updated with the layer-2 address of the other device, otherwise R will simply send the ICMP echo request to 02.
When 02 replies to 01, if it doesn't have an entry for R in its ARP table, then it will send an ARP request to R, and the ARP tables of both devices will be updated with the layer-2 address of the other device, otherwise 02 will simply send the ICMP echo reply to 01.
Layer-2 switches are normally transparent devices, and as such, they play no part in the ARP tables of the layer-3 devices, unless S is a managed switch with a management layer-3 address in the same layer-3 network as 02, then pinging 02 from S, if S doesn't have an entry in its ARP table for 02, S will send an ARP request for the layer-2 address of 02, and the ARP tables of both devices will be updated with the layer-2 address of the other device, otherwise S will simply send the ICMP echo request to 02.
When 02 replies to the management interface of S, if it doesn't have an entry for for the management interface of S in its ARP table, then it will send an ARP request to for the management interface of S and update its ARP table with the layer-2 address for the management interface of S.
If the management interface of S is in a different network, then the result will be the same as if 01 pinged 02: it is possible that the ARP tables of R and 02 get updated.
In any case, the switch will look at any frame entering the switch, and it will update its MAC address table based on the source layer-2 address of the frame. It will then look in its MAC address table for the destination MAC address to see if it has an entry. If no destination layer-2 address entry is found, it will flood the frame to all the other switch interfaces. If the layer-2 destination address is found in the MAC address table, then the frame is sent to the interface indicated by the MAC address table.