How to inflate all the `flat_*.Rmd` files?
Validation
=> New function to run all (or a selection of all), or a tip in the tips&tricks ?
- [x] In the vignette: https://thinkr-open.github.io/fusen/articles/tips-and-tricks.html#how-to-inflate-multiple-flat-files
- [ ] A function
inflate_all()can inflate all flats that are not deprecated (not stored in "dev/dev_history/flat_*" - [ ] The function reads all options in the "inflate" chunk.
- [ ] The function tests if there is something else than "inflate()" in the inflate chunk and warn the user
- [ ]
fusen::inflate()without parameter inflates the current flat file (as today) but uses all options in the "inflate" chunk, as forinflate_all()
Technicals
- Retrieve the full content of the "inflate" chunk
- Verify when inflating that there is indeed an inflate chunk
- Think about a way to store the inflate options inside the "fusen_config.yaml" file, as with files list
- Use a specific function
flat_params_to_config(), even used to define thestatealready implemented
- Use a specific function
How to inflate all the flat_*.Rmd files?
In a dev_history.R file, before references to {attachment}, devtools::check() and {renv}:
# Create a function to inflate a given `flat_*.Rmd` file stored in `dev/`
inflate_a_given_flat <- function(name_flat_rmd) {
flat_in_line <- readLines(file.path("dev", name_flat_rmd))
start_inflate_chunk_in_code <- which(stringr::str_detect(flat_in_line, "fusen::inflate\\(rmd ="))
inflate_code <- flat_in_line[start_inflate_chunk_in_code : (start_inflate_chunk_in_code + 3)] %>% stringr::str_c(collapse = "")
eval(parse(text = inflate_code))
return(message(glue::glue("{name_flat_rmd} inflate ok")))
}
# Launch the function for all `flat_*.Rmd` files stored in `dev/`
list.files("dev")[list.files("dev") %>% stringr::str_detect("^flat")] %>%
purrr::walk(inflate_a_given_flat)
Originally posted by @MargotBr in https://github.com/ThinkR-open/fusen/issues/84#issuecomment-982620651
As you propose some code, that's better with a new issue. @MargotBr
How to inflate all the flat_*.Rmd files?
In a dev_history.R file, before references to {attachment}, devtools::check() and {renv}:
# Create a function to inflate a given `flat_*.Rmd` file stored in `dev/`
inflate_a_given_flat <- function(name_flat_rmd) {
flat_in_line <- readLines(file.path("dev", name_flat_rmd))
start_inflate_chunk_in_code <- which(stringr::str_detect(flat_in_line, "fusen::inflate\\(rmd ="))
inflate_code <- flat_in_line[start_inflate_chunk_in_code : (start_inflate_chunk_in_code + 3)] %>% stringr::str_c(collapse = "")
eval(parse(text = inflate_code))
return(message(glue::glue("{name_flat_rmd} inflate ok")))
}
# Launch the function for all `flat_*.Rmd` files stored in `dev/`
list.files("dev")[list.files("dev") %>% stringr::str_detect("^flat")] %>%
purrr::walk(inflate_a_given_flat)
Originally posted by @MargotBr in https://github.com/ThinkR-open/fusen/issues/84#issuecomment-982620651
=> New function to run all (or a selection of all), or a tip in the tips&tricks ?
The problem is that if the users changes the content of the chunk, the inflate() is not in the same place, or there may be extra commands.
Can we get only inflate(.*) ?
Is there any reason for which the user could use an external parameter to fill one of the function parameter ? Like vignette = the_vignette_name_created_above ?
Or do we encourage users to write the inflate() command directly inside the "0-dev_history.Rmd", in a list with all others ?
Maybe we can even automate the add of the line of code automatically at first (every) inflate ? In which case, we also need to find the complete inflate() command before copy pasting it...
Then, the core of the function would be the same in both cases.
=> Or we create a YAML file with options for each
I store here the content of the original issue.
This issue was designed at first with the hypothesis that we would read on the yaml of each flat file the inflate parameters.
With the work started on issue #194 and #196, the inflate_all operation will be done based on the content of the config_fusen.yaml file.
This issue needs the issue #191 to be done first
Validation
- [ ] A function
get_inflate_params()retrieves the inflate parameters stored in the YAML header of each flat, to register them in the "config_fusen.yml" file - [x] In the vignette: https://thinkr-open.github.io/fusen/articles/tips-and-tricks.html#how-to-inflate-multiple-flat-files
- [ ] A function
inflate_all()can inflate all flats that are not deprecated (not stored in "dev/dev_history/flat_*" - [ ] The function detects if a flat file does not have any parameters in the "config_fusen.yml", or parameters in the YAML of the flat file to retrieve. And let the user know that it must inflate the concerned flat file manually or use the default arguments
- [ ] ~~The function uses all options if the "inflate" chunks.~~
- [ ] ~~The function tests if there is something else than "inflate()" in the inflate chunk and warn the user~~
- [ ] ~~
fusen::inflate()without parameter inflates the current flat file (as today) but uses all options in the "inflate" chunk, as forinflate_all()~~
Technicals
~~- Retrieve the full content of the "inflate" chunk to get the parameters. That may be easier inside the inflate() function itself because all params are there: See https://github.com/ThinkR-open/fusen/issues/190~~
~~- Think about a way to store the inflate options inside the "fusen_config.yaml" file, as with files list
- Use a specific function flat_params_to_config(), even used to define the state already implemented~~
~~- Note that I can run the inflate() without parameters~~
History :
🔴 Closed issues:
https://github.com/ThinkR-open/fusen/issues/192
In this issue, I tried to parse the content of the inflate chunk. We changed the way we want to reach our goal to have an inflate_all, but it could still be useful in a transition phase.
~~- [ ] Detect inflate options in the inflate chunk. Make the chunk named inflate mandatory~~
~~- [ ] Allow the inflate option to be listed in the YAML of the flat file~~
~~- [ ] Make sure it is consistent with the ones in the dev-inflate chunk~~
- [ ] Inform if previous {fusen} version inflated is not the same as current: Probably need to re-inflate all files for version <= 0.4.1
- [x] Add fusen Version in DESCRIPTION when inflating
- [ ] Register inflate parameters, so that we can inflate all
- https://github.com/ThinkR-open/fusen/issues/96
That should be good for this one now.