Skip to contents

This function creates a temporary directory structure based on the provided directory structure. It sets up directories and files as specified and provides a function to mimic `here::here()` behavior for accessing files within the mock directory. The temporary directory is automatically cleaned up after use.

Usage

create_mock_dir(dir_structure, .env = parent.frame())

Arguments

dir_structure

A named list defining the directory and file structure. Directories are represented by lists, while files are represented by `TRUE`.

.env

The environment in which to schedule the cleanup. Default is `parent.frame()`.

Value

A list containing:

path

The path to the created mock directory.

here

A function that mimics `here::here()` to access files within the mock directory.

Details

The function creates a temporary directory at a location determined by `tempdir()`, sets up the specified directory and file structure, and returns a list containing the path to the mock directory and a function to access files within it. The working directory is temporarily changed to the mock directory during the operation, and the original working directory is restored after cleanup.