library(babynames)
library(tidyverse)
library(bslib)

# separate names into new & old
oldnames <- filter(babynames, year < 1900)
newnames <- filter(babynames, year > 1999)

###
#Create a function that creates a new name by gluing two or more names together.

#Experiment with combining two old names & with one new name.
#Then experiment by combining the result of that into one name.

#Pick out two old names and one new name. Glue each old name to the new name.
# Then glue the results together into one final abomination of a name.
###

gluenames <- function() {
  two_old_names <- oldnames |> slice_sample(n = 2) |> select(name) |> pull()
  one_new_name <- newnames |> slice_sample(n = 1) |> select(name) |> pull()

  new_name <- str_c(two_old_names[1], ' ', one_new_name, ' ', two_old_names[2])
  return(new_name)
}
gluenames()


# - - - - - # - - - - - # - - - - - # - - - - -
# another way

create_new_name <- function(data) {
  # Select two random names
  random_names <- data |>
    slice_sample(n = 2) |>
    pull(name)

  # Get the two names
  first_name <- random_names[1]
  last_name <- random_names[2]

  # Combine into a full name
  full_name <- paste(first_name, last_name)

  return(full_name)
}

# Generate one name
create_new_name(babynames)

# Empty vector to use in the loop
names_list <- vector("character", 5)

# Generate five names, or whatever is specified in the loop
for (i in 1:5) {
  names_list[i] <- create_new_name(babynames)
}

print(names_list)
