The Federation starship Enterprise, under the command of Captain Jean-Luc Picard, is en route to provide medical care for the reclusive but respected scientist Dr. Ira Graves, who lives with only one other person, Kareen Brianon, on a remote planet. When the crew receives an emergency distress call from a nearby transport ship, Captain Picard elects to try a risky near-warp transport of an away team, including Data, Counselor Troi, Lt. Worf, and Dr. Selar, to see to Dr. Graves while the Chief Medical Officer Dr. Pulaski travels with the rest of the crew to attend to the transport.
The away team finds that the request for medical assistance was made by Kareen without Dr. Graves' knowledge, and though resentful, allows Dr. Selar to examine him. Dr. Graves recognizes Data as Noonien Soong's creation, and claims he had taught Soong everything he knew. Selar reports that Dr. Graves has a terminal form of Darnay's disease and only has three weeks to live. The team helps to collect Dr. Graves' research and records to take with them after his death. Dr. Graves, while working alone with Data, whistles "If I Only Had a Heart", which intrigues Data, and the two discuss the nature of the Tin Woodsman and Data's android condition. Dr. Graves shows Data that he has developed a sophisticated computer that has the ability to transfer his consciousness, allowing him to live after his body dies. The doctor also discovers that Data has a shut-off switch which Data describes is his own version of death.
Data returns to the away team and announces that Dr. Graves has died. The away team and Kareen are picked up by the Enterprise, and a funeral for the scientist is held in space. Data provides a glowing eulogy of Dr. Graves at the ceremony, and whistles "If I Only Had a Heart" while entering one of the ship's elevators. Data's uncharacteristic behavior piques the interest of the other crew members, and Picard decides that an examination of Data is required. Although a physical examination shows nothing wrong with Data's body, Troi's psychotronic stability tests suggests there are two personalities within Data, the one they know as Data, and one that is alien and dominant, and threatening to take over Data's personality. Picard realizes that Dr. Graves has transferred his mind into Data; meanwhile, Dr. Graves, in Data, reveals to Kareen the truth, and accidentally breaks two bones in her hand while passionately explaining how they could live together forever if she would transfer her mind into a robot body. Picard attempts to talk Dr. Graves into voluntarily give up Data's body, noting the harm he is causing to those he loves, but Dr. Graves uses Data's strength to knock the captain unconscious. When Picard awakes, he and a security team find Data in his quarters. Data is back to his old self, and Kareen finds that Dr. Graves has transferred himself out of Data and into the Enterprise's computer, transferring knowledge, but no consciousness. The "human" part of Dr. Graves has been lost.