R: prepare keras image directory for image_flow_from_directory

I working on a R script that prepares the image directory for the keras framework, for the flow_from_directory function. In that directory the images are sepereted in target classes that the data have e.g. folder for cats or dogs, like the following structure shows.

data-|
|    +-train
|    |     +-dog
|    |     +-cat
|    +-validation
|    |     +-dog
|    |     +-cat
|    +-test
|    |     +-dog
|    |     +-cat

My data lies in folder train, test and val, already. The classes for the images are numerical in range from 0 to 7 and stored in an txt file. To know which image belongs to which txt file the filename is used , e.g. 1.png <-> 1.txt -> "0". My first try to do this is straight forward with the knowlage about R I know already. But I read that in R for loops are no very commen to use so I tried another way to do this. What in this script is missing is the last loop over each subdirectory.

image_postfix <- ".png"
label_postfix <- ".txt"


# Base directory     
data_directory <- "C:/data/deep_learning - Kopie/aufgabe_1"
# Subdirectorys with the data 
data_subdir <- c("train", "validation", "test")
# Resulting directory with only the catagorical folders
keras_directory <- "image_category"

# get image files from the train directory
image_files <- list.files(file.path(data_directory,data_subdir[1]), pattern = image_postfix)
# get txt files from the train directory
label_files <- list.files(file.path(data_directory,data_subdir[1]), pattern = label_postfix)
# get get the plain file names
file_name <- gsub( pattern = "(.*)\\..*", replacement = "\\1", label_files)

# reade each txt file in the directory
labels <- mapply(readChar,file.path(data_directory,data_subdir[1],label_files),nchar = 1)

names(labels) <- file_name

# create a data frame
train_data <- data.frame(image_files, label_files, labels)

# get a list with the classes 
classes <- levels(train_data$labels)

# create the subdirectory for keras
dir.create(file.path(data_directory,data_subdir[1],keras_directory), showWarnings = FALSE)
# create the directory for each class
lapply(file.path(data_directory,data_subdir[1],keras_directory, classes), dir.create, showWarnings = FALSE)

# loop over each class
for (idx in classes) {
    # get the data for that class
    train_data_by_label <- subset(train_data, train_data$labels == idx)
    # and copy the image file in the resulting directory  
    file.copy(
         file.path(data_directory,data_subdir[1],train_data_by_label$image_file),
         file.path(data_directory,data_subdir[1],keras_directory,idx,train_data_by_label$image_file)
    )
}

What i have got for now is the following code.

image_postfix <- ".png"
label_postfix <- ".txt"

# Base Directory
data_directory <- "C:/data/deep_learning - Kopie/aufgabe_1"
# Subdirectorys for the data
data_subdir <- c("train", "validation", "test")

keras_directory <- "image_category"

# creates a list with each subdirectory as name and its including images  
image_files <- mapply(list.files,file.path(data_directory,data_subdir), pattern = image_postfix)

# creates a list with each subdirectory as name and its including txt files  
label_files <- mapply(list.files,file.path(data_directory,data_subdir), pattern = label_postfix)

# creates a list with each subdirectory as name and its resulting file names
file_names <- lapply(X = label_files,FUN = gsub,  pattern = "(.*)\\..*", replacement = "\\1")

# now i'm out of knowlage about R 

# Read each file in labels_files with the name as path and that including files

Data structure for image_files, label_files and file_names

Thanks for all your suggestions !