combined_file_system: Combine train and test filesystem into single folder

View source: R/data_converters.R

combined_file_systemR Documentation

Combine train and test filesystem into single folder

Description

This function reorganises files that have been split into train and test directories using train_test_filesystem() back into a single directory. This is a convenience function to reverse the effects of train_test_filesystem().

Usage

combined_file_system(
  path_to_folders,
  file_ext,
  train_folder = "train",
  test_folder = "test",
  overwrite = FALSE
)

Arguments

path_to_folders

path containing test and train folders; files will be moved here

file_ext

file extension to filter

train_folder

train folder subdirectory name

test_folder

test folder subdirectory name

overwrite

force overwrite of files that already exist

Value

Logical vector, indicated success or failure for each file

Examples

set.seed(123)
# create 10 random DNA files
tmp_dir <- tempdir()
# remove any existing .fna files
file.remove(
 list.files(tmp_dir, pattern = "*.fna", full.names = TRUE)
)
for (i in 1:10) {
writeLines(paste0(">", i, "\n", paste0(sample(c("A", "T", "C", "G"),
  100, replace = TRUE), collapse = "")), file.path(tmp_dir, paste0(i, ".fna")))
}

# split files into train and test directories
paths <- train_test_filesystem(tmp_dir,
                               file_ext = "fna",
                               split = 0.8,
                               shuffle = TRUE,
                               overwrite = TRUE)
# combine files back into a single directory
combined_file_system(tmp_dir, "fna")
list.files(tmp_dir)

MIC documentation built on April 12, 2025, 2:26 a.m.