This function checks for duplicated elements in a vector. If duplicated elements are found, it appends an underscore and a sequence number to each occurrence of the duplicated element.
name_duplicated(x)
A character vector.
A character vector where duplicated names are made unique by appending a sequence number.
vec <- c("apple", "orange", "apple", "banana", "orange")
name_duplicated(vec)
#> [1] "apple_1" "orange_1" "apple_2" "banana" "orange_2"