# Deal with a ‘fusen’ flat file

    library(fusen)

## Rename a flat file

‘fusen’ provides a function `rename_flat_file()` to rename a flat file. This function updates the file name in the configuration file, modifies the inflating files if needed and renames the flat file itself. This function should avoid remaining inflated files in the repository, and ensure that the configuration file is up-to-date.

    #' \dontrun{
    # These functions change the current user workspace
    dev_file <- suppressMessages(
      add_flat_template(
        template = "add",
        pkg = ".",
        overwrite = TRUE,
        open = FALSE
      )
    )
    rename_flat_file(
      flat_file = "dev/flat_additional.Rmd",
      new_name = "flat_new.Rmd"
    )
    #' }

## Fully deprecate a flat file after inflate

‘fusen’ serves as a framework to ensure that developers prioritize end-users during the function development process. By employing ‘fusen’ within Rmd/qmd files, developers can conceptualize their product and articulate their ideas in plain text before initiating any code. This approach encourages consideration of the package’s users: their intended actions, and the potential impact on their experiences. Consequently, developers can draft function documentation prior to its implementation, thinking about explaining what’s behind the black box, as well as reminding that this may end into the vignette.

Additionally, ‘fusen’ offers a minimal template comprising ‘function’, ‘doc’, and ‘test’ components. We advocate for Test Driven Development (TDD), where writing tests precedes function implementation. This practice aids in function design and enables anticipation of future behavior.

Subsequently, you can proceed to implement the function itself, thereafter inflating the flat file to generate R, test, and vignette files. This initial iteration yields comprehensive documentation, a complete test suite, and a functional implementation.

Following this initial phase, you have the option to:

- Continue iterating on the function, documentation, and tests within the flat file, updating the R, test, and vignette files accordingly through inflation.
- Opt to iterate directly within the “R/”, “tests/”, and “vignette/” directories.

If the preference is to transition away from the flat file and conduct further development in the specified directories, proper deprecation of the flat file is recommended.

To facilitate this transition, the function `deprecate_flat_file()` is provided. This function cleans script files by removing “do not edit” markers, updates the ‘fusen’ configuration file, and relocates the flat file to a “dev/flat_history/” directory, preserving the cleanliness of the “dev/” directory.

    #' \dontrun{
    #' # These functions change the current user workspace
    dev_file <- suppressMessages(
      add_flat_template(
        template = "add",
        pkg = dummypackage,
        overwrite = TRUE,
        open = FALSE
      )
    )
    deprecate_flat_file(flat_file = "dev/flat_additional.Rmd")
    #' }