Closed gdurif closed 1 year ago
That is a good point.
This is due to {attachment} as att_from_rmd()
changes the warn level.
We will need to change this part of the code to set back the warning level to the one of the user, even if we suggest to purl with level -1
to avoid to much information for this purl()
part: https://github.com/ThinkR-open/attachment/blob/4772336e1163fc81e40006c50c7dd4d2da553024/R/att_from_rmds.R#L37
We will get into this.
At the end, that would be something like
cat(
paste0('warn_user <- getOption("warn");',
'options(warn=', warn, ');',
'invisible(knitr::purl("', gsub("\\", "\\\\", path, fixed = TRUE), '"',
', output = "', gsub("\\", "\\\\", r_file, fixed = TRUE), '"',
', encoding = "', encoding, '"',
', documentation = 0, quiet = TRUE));',
'options(warn=warn_user)'
, file = runR)
And we will want to add a unit test to verify that getOption("warn")
is the same before and after att_from_rmd()
, and also before and after att_amend_desc()
In PR https://github.com/ThinkR-open/attachment/pull/96, this was fixed Soon on 'r-universe', then CRAN :smiley:
[ ] Code was changed, and a unit test verifies that the warn level is not changed after att_amend_desc()
[ ] Reprex presented above runs as expected
# warning option
options("warn")
#> $warn
#> [1] 0
# Create a new project
dummypackage <- tempfile("dummypackage")
dir.create(dummypackage)
# {fusen} steps 1
dev_file <- fusen::add_flat_template(
template = "full", pkg = dummypackage, overwrite = TRUE)
#> Created file .here in /tmp/RtmpLKbCc0/dummypackage94cd4ae2f425 . Please start a new R session in the new project directory.
# warning option
options("warn")
#> $warn
#> [1] 0
# {fusen} steps 2
fusen::fill_description(
pkg = dummypackage, fields = list(Title = "Dummy Package"))
#> [1] "/tmp/RtmpLKbCc0/dummypackage94cd4ae2f425/DESCRIPTION"
# warning option
options("warn")
#> $warn
#> [1] 0
# {fusen} steps 3
flat_file <- dev_file[grepl("flat", dev_file)]
fusen::inflate(
pkg = dummypackage, flat_file = flat_file,
vignette_name = "Exploration of my Data", check = FALSE
)
#> ✔ Setting active project to '/tmp/RtmpLKbCc0/dummypackage94cd4ae2f425'
#> ℹ Loading dummypackage94cd4ae2f425
#> Writing 'NAMESPACE'
#> Le chargement a nécessité le package : testthat
#>
#> ✔ Adding 'knitr' to Suggests field in DESCRIPTION
#> ✔ Setting VignetteBuilder field in DESCRIPTION to 'knitr'
#> ✔ Adding 'inst/doc' to '.gitignore'
#> ── Updating config file for dev/flat_full.Rmd ──────────────────────────────────
#> ✔ path: dev/flat_full.Rmd was added to the config file
#> ✔ state: active was added to the config file
#> ✔ R: R/my_median.R was added to the config file
#> ✔ R: R/my_other_median.R was added to the config file
#> ✔ tests: tests/testthat/test-my_median.R was added to the config file
#> ✔ tests: tests/testthat/test-my_other_median.R was added to the config file
#> ✔ vignettes: vignettes/exploration-of-my-data.Rmd was added to the config file
#> ℹ config file created: dev/config_fusen.yaml
#> Saving attachment parameters to yaml config file
#> Updating dummypackage94cd4ae2f425 documentation
#> ℹ Loading dummypackage94cd4ae2f425Writing 'NAMESPACE'Writing 'my_median.Rd'Writing 'my_other_median.Rd'Writing 'sub_median.Rd'ℹ Loading dummypackage94cd4ae2f425[+] 3 package(s) added: stats, rmarkdown, testthat.
#> [1] "/tmp/RtmpLKbCc0/dummypackage94cd4ae2f425"
# warning option
options("warn")
#> $warn
#> [1] 0
Created on 2023-04-21 with reprex v2.0.2
It appears that calling the function
fusen::inflate()
modifies the warning level in the user global R options from0
(default) to-1
(ignore all warnings), without advertising it, which is a problem when you are then doing some development (e.g. in Rstudio) expecting some code to throw a warning.I encountered this problem both inside Rstudio and in R console from the command line.
Here is a minimum working example (from the
fusen::inflate()
man page).And here is my
sessionInfo()
: