This is a basic example which shows you how to solve a common problem. The "test" folder first contains R Markdown files with unnamed chunks. After running name_dir_chunks, they're all named, with names using the filenames as basis.

fs::dir_copy(system.file("examples", package = "namer"),
            "test")
name_dir_chunks("test")
file.edit("test/example1.Rmd")

There's also name_chunks() for use on a single R Markdown file; and unname_chunks() to unname all chunks of a single R Markdown file as well as unname_dir_chunks() to unname all chunks of all R Markdown files in a directory, which can be useful when cleaning your chunk labels.

By default unname_chunks() unnames all chunks with exception of the 'setup' chunk. By using the argument chunk_name_prefix one can indicate the prefix of the labels that will be unnamed. Useful when one refers to a label by using chunk option ref.label so that it is inconvenient when that label is unnamed. By setting chunk_name_prefix equal to 'the filename with extension stripped' followed with a '-' (dash) only the labels generated by name_chunks() will be unnamed.

If you're working with RStudio, installing the package will have installed an addin for labelling chunks of any R Markdown document you select.

When using {namer}, please check the edits before pushing them to your code base. Such automatic chunk labelling is best paired with version control.



lockedata/namer documentation built on March 8, 2024, 8:51 p.m.