create_directory: Create a directory

View source: R/create_directory.R

create_directoryR Documentation

Create a directory

Description

Function ment to create subdirectories to save the results of the current step.

Usage

create_directory(called_from,
                 dir_results = base::getwd(),
                 results_name = VCFtoGWAS::name_by_time())

Arguments

called_from

The function (and step in the process) from which the function was called. Is added to the name of the subdirectory that is created by the function.

dir_results

The directory in which a subfolder will be created and results will be saved. Make sure it exists!!!
If entered directory doesn't exist (or no direcotry was entered), the subfolder will be created in the current working directory.

results_name

The results_name parameter dictates the folder (within dir_results folder) that will be created to save the results.
If the results name isn't changed from the default (‘name_by_time’), then a name based on time will be constructed. Step name is always added. Examples:

  • By default: "2021-12-15_10.58_Step1-Upload_VCF-results"

  • Non default: "OnlyHomozygousStrains_Step1-Upload_VCF-results"

Author(s)

Tomer Antman

Examples

## The function is currently defined as
function (called_from, dir_results = getwd(), results_name = name_by_time())
{
    results_name <- paste0(results_name, "_", deparse(substitute(called_from)),
        "-results")
    results_directory <- paste0(dir_results, "/", results_name)
    dir.create(results_directory)
    if (grepl("No such file or directory", names(last.warning))) {
        message(results_name, " folder couldn't be created because\n",
            dir_results, " directory doesn't exist.\nTrying to create ",
            results_name, " folder in\n", getwd())
        results_directory2 <- paste0(getwd(), "/", results_name)
        dir.create(results_directory2)
        if (grepl("No such file or directory", names(last.warning))) {
            stop("Couldn't create a directory to save the results")
        }
        else {
            results_directory <- results_directory2
            message("Results will be saved into: \n", results_directory)
        }
    }
    else if (grepl("already exists", names(last.warning))) {
        message("The results directory already exists, the results will be saved in:\n",
            results_directory)
    }
    else {
        message("Results directory created:\n", results_directory)
    }
    return(results_directory)
  }

TomerAntman/VCFtoGWAS documentation built on July 6, 2022, 4:51 a.m.