Skip to contents

Creates directories in which growR by default looks for or deposits certain files. Also, optionally populates these directories with example files, which are useful to familiarize oneself with the growR simulation framework.

Usage

setup_directory(root, include_examples = TRUE, force = FALSE)

Arguments

root

Path to directory in which to initialize.

include_examples

If TRUE (default), include example data and input parameters in the appropriate directories.

force

boolean If TRUE, the user will not be asked for permission before we write to the filesystem.

Examples

# Prepare a temporary directory to write to
tmp = file.path(tempdir(), "test-setup_directory")
dir.create(tmp)

# We need `force = TRUE` here in order to make the example work in 
# non-interactive settings.
setup_directory(root = tmp, include_examples = FALSE, force = TRUE)
#> [INFO]Initialized directory structure in `/tmp/RtmpxPgtzx/test-setup_directory`.
#> [1] 0

# The `input`, `output` and `data` directories are now present.
list.files(tmp)
#> [1] "data"   "input"  "output"

# Warnings are issued if directories are already present. Example files 
# are still copied and potentially overwritten.
setup_directory(root = tmp, include_examples = TRUE, force = TRUE)
#> Warning: Directory `/tmp/RtmpxPgtzx/test-setup_directory` is not empty.
#> Warning: Directory `/tmp/RtmpxPgtzx/test-setup_directory/input/` already exists.
#> Warning: Directory `/tmp/RtmpxPgtzx/test-setup_directory/output/` already exists.
#> Warning: Directory `/tmp/RtmpxPgtzx/test-setup_directory/data/` already exists.
#> [INFO]Initialized directory structure in `/tmp/RtmpxPgtzx/test-setup_directory`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/posieux_weather.txt` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/posieux_parameters.csv` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/posieux_management1.txt` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/posieux_management2.txt` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/sorens_weather.txt` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/sorens_parameters.csv` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/sorens_management1.txt` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/sorens_management2.txt` to `/tmp/RtmpxPgtzx/test-setup_directory/input/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/posieux1.csv` to `/tmp/RtmpxPgtzx/test-setup_directory/data/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/posieux2.csv` to `/tmp/RtmpxPgtzx/test-setup_directory/data/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/sorens1.csv` to `/tmp/RtmpxPgtzx/test-setup_directory/data/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/sorens2.csv` to `/tmp/RtmpxPgtzx/test-setup_directory/data/`.
#> [INFO]Copying `/home/runner/work/_temp/Library/growR/extdata/example_config.txt` to `/tmp/RtmpxPgtzx/test-setup_directory`.
#> [INFO]Copied example files to respective directories.

# Example files are now present
list.files(tmp, recursive = TRUE)
#>  [1] "data/posieux1.csv"             "data/posieux2.csv"            
#>  [3] "data/sorens1.csv"              "data/sorens2.csv"             
#>  [5] "example_config.txt"            "input/posieux_management1.txt"
#>  [7] "input/posieux_management2.txt" "input/posieux_parameters.csv" 
#>  [9] "input/posieux_weather.txt"     "input/sorens_management1.txt" 
#> [11] "input/sorens_management2.txt"  "input/sorens_parameters.csv"  
#> [13] "input/sorens_weather.txt"     

# End of the example. The following code is for cleaning up.
unlink(tmp, recursive = TRUE)