i <- 1
while (i <= length(files)) {
start <- i
end <- start + 3
v <- files[start:end]
y <- fname[start:end]
date_range <- substr(y[1], 7, 23)
html_block <- make_div(v, date_range)
top <- readLines("header.html")
bottom <- readLines("footer.html")
# This will write just the div block
write(x = html_block, file = paste0(date_range, "-block.html"))
# This will write a working website
write(x = c(top, "<body>", html_block, "</body>", bottom),
file = paste0(date_range, "-website.html"))
i <- i + 4
}
So, this link will provide a reference on how I've gotten here. And the above code is in fact doing exactly what I want it to. The goal was for it to loop through the lengthy list of files that I have and then make a div for each file whose only difference is file type (i.e. everything else in the file name was the same). However, that is not what this is doing as this just takes every 4 files and puts them together. The issue with this is that not every 4 files are of the same file (some are just 2 or 3 for example; see fname below for example). So what I was wondering is whether there is a way to cycle through each file name and see whether if the characters from x to y are the same, and if so, those can then be grouped together and then so on.
# fname[1:10]
fname <- c("TOR-D-18580907-18580908.tif",
"TOR-D-18580907-18580908.tif-FailToProcess-Data.RDS",
"TOR-D-18580907-18580908.tif-FailToProcess-Plot.png",
"TOR-D-18580907-18580908.tif.png",
"TOR-D-18580908-18580909.tif",
"TOR-D-18580908-18580909.tif-FailToProcess-Data.RDS",
"TOR-D-18580908-18580909.tif-FailToProcess-Plot.png",
"TOR-D-18580908-18580909.tif.png",
"TOR-D-18580910-18580911.tif",
"TOR-D-18580910-18580911.tif-FailToProcess-Data.RDS")
The first 10 elements of fname (a variable that contains all of the file names which is significantly more than 10) is displayed above. Is there a way for me to check if the 7th to the 24th element (i.e. 18580907-18580908 which is the date) matches the following one and, if so, can those be grouped together and then continue that cycle for every single file that follows?