Skip to content

Refactor folder organization for compliance with R package structure

@pierre.rouault, I would like to inverse the logic of the current folder organization. As for convenience in the management of the package dependencies and function loading of CAWET, the code is organized as an R package. In this framework, all extra scripts and data are supposed to be located in a folder called "inst" (See: https://r-pkgs.org/misc.html#sec-misc-inst).

One advantage of isolating the CAWET cripts and template data, is that it would be very easy to generate an instance of CAWET on the disk by calling a single script/function.

So instead of having a bunch of folders in the root directory, I would put them in "inst/ext-data" and it would be easy to create a instance of CAWET with a function containing:

copy_extdata <- function(destdir) {
  # Path to the installed package's ext-data directory
  srcdir <- system.file("ext-data", package = "CAWET")

  if (srcdir == "") {
    stop("Cannot find ext-data directory in package CAWET.")
  }

  # Create destination directory if needed
  if (!dir.exists(destdir)) {
    dir.create(destdir, recursive = TRUE)
  }

  # List and copy files (and subfolders)
  files <- list.files(srcdir, full.names = TRUE)
  file.copy(files, destdir, recursive = TRUE, overwrite = TRUE)
}