Skip to contents

This function replaces specified speaker identifiers with new names throughout an interview transcript. It is useful for anonymizing data, standardizing speaker names, or correcting transcription errors. The replacement is performed using regular expressions to ensure exact matching of the speaker tag format "[Name]".

Usage

rename_speaker(interview, current_speaker, new_speaker)

Arguments

interview

A character vector representing the interview transcript lines. Each line should start with a speaker tag in the format [Speaker Name].

current_speaker

A character vector containing the current speaker names to be replaced. These should not include the square brackets or trailing space; the function handles the formatting automatically.

new_speaker

A character vector containing the replacement speaker names. This vector must have the same length as current_speaker, with each element corresponding to the speaker at the same position in current_speaker.

Value

A character vector with the same structure as the input interview, but with the specified speaker names replaced.

Examples

speaker = retrieve_speaker(intrw)
intrw_renamed = rename_speaker(
    interview = intrw, 
    current_speaker = speaker[!speaker == "UNKNOWN"],
    new_speaker = c("Mary", "Marylou")
)