dict_seed() lists names that two or more documents each assign a literal
value, as candidates for dict.yml. It parses the code and never runs it,
and it writes nothing.
Value
A data frame with a row per name: name, value (its text, NA
when the values differ), differs, n (files), files and where (every
assignment as <file>:<line>: <value>). The attribute skipped is a data
frame (file, line, message) of pieces of code that did not parse.
Details
With paths = NULL it reads every .qmd, .Rmd and .rmd file under the
project root, except in folders whose name starts with _ or . or is
renv. Given paths it reads those files, which may be .R files too; a
.R file is read only when named. In a document it reads each r chunk
except one with eval = FALSE or another engine in its header, or
#| eval: false. A file that is not UTF-8 is read as Latin-1.
A name counts when a top-level expression of a piece (not inside {, if,
function or any other call) is name <- literal, name = literal or
literal -> name, a literal being a number, a string, - or + of a
number, or c() of numbers or of strings with every argument named or none.
Logicals, NA, NULL, dates, <<- and assign() do not count.
Limits: a constant written by a computation, or inside a function or a block, is not seen; inline R is not read; a name reused for unrelated things in two documents is listed, and the author decides.
Examples
dir <- tempfile("weft-example")
dir.create(dir)
writeLines("", file.path(dir, "_weft.yml"))
for (f in c("a.R", "b.R")) writeLines("depth <- 4.5", file.path(dir, f))
dict_seed(file.path(dir, c("a.R", "b.R")))
#> name value differs n
#> 1 depth 4.5 FALSE 2
#> files
#> 1 /tmp/Rtmp62bcEi/weft-example1a3c4959bcdf/a.R, /tmp/Rtmp62bcEi/weft-example1a3c4959bcdf/b.R
#> where
#> 1 /tmp/Rtmp62bcEi/weft-example1a3c4959bcdf/a.R:1: 4.5; /tmp/Rtmp62bcEi/weft-example1a3c4959bcdf/b.R:1: 4.5
unlink(dir, recursive = TRUE)