---
title: "Sequential Scripts"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{sequential_scripts}
  %\VignetteEngine{knitr::rmarkdown}
  \usepackage[utf8]{inputenc}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
knitr::opts_knit$set(root.dir = tempdir())
```

```{r setup, message=FALSE}

library(ptspotter)


```

## Creating File Sequences

Use `seq_file_ops()` to quickly produce sequential scripts.

```{r}
# old_wd <- setwd(tempdir())

# create a folder with some sequentially labelled scripts
seq_file_ops(n = 10, target_dir = "munge", filetype = "R")

# take a peek to confirm
list.files("munge")
```
## Adjusting File Sequences

During your work, as the program you are writing grows it may become necessary
to separate code from one script into two or more. This could involve some
laborious manual renumbering of the sequential scripts within the munge
directory.

Instead, we can use `adj_file_nos()` to make room for our new script(s). In the
following example, I will need to add just **one** more single script. I achieve
this by leaving the `step` and `action` parameters as their default values. I
need to insert the new script at "**02-.R**". 

```{r}
adj_file_nos(target = 2, directory = "munge")

list.files("munge")
```

Now I can create a new file at "**02-.R**" without needing to manually relabel
anything. 

```{r}
file.create("munge/02-.R")

list.files("munge")
```

Your customer has changed their mind about a feature, meaning all your hard 
work on scripts **"06-.R" to "08-.R"** are no longer required. Let's delete those
scripts.

```{r}
rm_these <- c("06-.R", "07-.R", "08-.R")
file.remove(paste("munge", rm_these, sep = "/"))
list.files("munge")
```
Now there is a gap in the sequence. To fix this could involve more laborious
relabelling. Instead, let's use `adj_file_nos()` to correct the sequence.

```{r}
adj_file_nos(target = 9, directory = "munge", action = "down", step = 3)
list.files("munge")
```

Much better!

```{r, include=FALSE}
unlink("munge", recursive = TRUE)
```


