-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Custom config_file renamed during render #1307
Comments
Hi, If that can help understand the current behavior, here are some context: Currently, config file needs to be name Lines 98 to 106 in 6ae8900
So it seems indeed that we are currently
The content is saved in a tempfile and restored at the end of the rendering - so you can have a default file and some custom files.
We are dependant of Another solution would be to support directly the user provided filename as a config file, without any copying and replacing. Maybe something like this diff --git a/R/render.R b/R/render.R
index ac87d259..dacd2793 100644
--- a/R/render.R
+++ b/R/render.R
@@ -95,17 +95,8 @@ render_book = function(
"versions of bookdown."
)
- if (config_file != '_bookdown.yml') {
- unlink(tmp_config <- tempfile('_bookdown_', '.', '.yml'))
- if (file.exists('_bookdown.yml')) file.rename('_bookdown.yml', tmp_config)
- file.rename(config_file, '_bookdown.yml')
- on.exit({
- file.rename('_bookdown.yml', config_file)
- if (file.exists(tmp_config)) file.rename(tmp_config, '_bookdown.yml')
- }, add = TRUE)
- }
-
on.exit(opts$restore(), add = TRUE)
+ opts$set(config_file = config_file)
config = load_config() # configurations in _bookdown.yml
output_dir = output_dirname(output_dir, config)
on.exit(xfun::del_empty_dir(output_dir), add = TRUE)
diff --git a/R/utils.R b/R/utils.R
index 8f6a67e1..8f47e0f4 100644
--- a/R/utils.R
+++ b/R/utils.R
@@ -69,10 +69,11 @@ get_base_format = function(format, options = list()) {
do.call(format, options)
}
-load_config = function() {
- if (length(opts$get('config')) == 0 && file.exists('_bookdown.yml')) {
+load_config = function(config_file = '_bookdown.yml') {
+ config_file = opts$get('config_file') %n% config_file
+ if (length(opts$get('config')) == 0 && file.exists(config_file)) {
# store the book config
- opts$set(config = rmarkdown:::yaml_load_file('_bookdown.yml'))
+ opts$set(config = rmarkdown:::yaml_load_file(config_file))
}
opts$get('config')
} I wonder if that would be enough - @yihui you know better - I let you comment before doing any PR. |
Now I think we should copy instead of renaming.
That sounds like a better idea. |
Hi all, I'll note I have a related issue: I have a folder in my root directory called 'config_files' - it conatins .yml files are unrelated to my bookdown and belong to a different aspect of my repository/project. When I render my book (the Rmd's and associated yml files are in a folder called 'bookdown', which I've set up to export the output to a folder in the root directory called 'docs'), it moves the entirety of the 'config_files' folder, along with all files within the folder to a folder called Is there any way to prevent this behavior from happening when I render a bookdown? |
@steeleb I believe this happens only because folder ends with We list files in Lines 448 to 454 in e717c5e
In R Markdown ecosystem, @yihui should we make that a rule and warn about this in a bookdown project ? Or find a way to exclude some directories ? |
this should fix the problem reported at #1307 (comment), in which case config_files was moved by mistake
Thanks @yihui! |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
I have two different config files for rendering different versions of a book (including or excluding chapters). They have two different names,
_bookdown_v1.yml
and_bookdown_draft.yml
, so I have to set the config_file argument when I render:bookdown::render_book(config_file = "_bookdown_v1.yml")
During the rendering process, the config file is renamed to
_bookdown.yml
. This can cause several problems:_bookdown.yml
, it is overwritten, so you can't keep a default file if you ever want to use a custom config file_bookdown.yml
is not renamed back to_bookdown_v1.yml
There might be a good reason that the file has to be renamed, but I think if you copied it to
_bookdown.yml
rather than renaming it, it would avoid the first and third problems.As always, thank you so much for all you do for the R community!
session_info
R version 4.1.0 (2021-05-18)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6, RStudio 1.4.1106
Locale: en_GB.UTF-8 / en_GB.UTF-8 / en_GB.UTF-8 / C / en_GB.UTF-8 / en_GB.UTF-8
Package version:
base64enc_0.1.3 bookdown_0.24 digest_0.6.29 evaluate_0.14 fastmap_1.1.0 glue_1.6.0
graphics_4.1.0 grDevices_4.1.0 highr_0.9 htmltools_0.5.2 jquerylib_0.1.4 jsonlite_1.7.3
knitr_1.37 magrittr_2.0.1 methods_4.1.0 rlang_0.4.12 rmarkdown_2.11 stats_4.1.0
stringi_1.7.6 stringr_1.4.0 tinytex_0.36 tools_4.1.0 utils_4.1.0 xfun_0.29
yaml_2.2.1
The text was updated successfully, but these errors were encountered: