Title: Names Your 'R Markdown' Chunks
Version: 0.1.9
Description: It names the 'R Markdown' chunks of files based on the filename.
License: MIT + file LICENSE
URL: https://github.com/jumpingrivers/namer, https://jumpingrivers.github.io/namer/
BugReports: https://github.com/jumpingrivers/namer/issues
Imports: cli, dplyr, fs, glue, magrittr, purrr, rstudioapi, tibble
Suggests: covr, knitr, rmarkdown, testthat
VignetteBuilder: knitr
Encoding: UTF-8
Language: en-GB
RoxygenNote: 7.3.2
NeedsCompilation: no
Packaged: 2025-01-23 16:43:52 UTC; colin
Author: Colin Gillespie [aut, cre], Steph Locke [aut], Maƫlle Salmon ORCID iD [aut], Ellis Valentiner [ctb], Charlie Hadley ORCID iD [ctb], Jumping Rivers [fnd] (https://jumpingrivers.com), Han Oostdijk ORCID iD [ctb], Patrick Schratz ORCID iD [ctb]
Maintainer: Colin Gillespie <colin@jumpingrivers.com>
Repository: CRAN
Date/Publication: 2025-01-23 17:00:02 UTC

Pipe operator

Description

See magrittr::%>% for details.

Usage

lhs %>% rhs

Arguments

lhs

A value or the magrittr placeholder.

rhs

A function call using the magrittr semantics.

Value

The result of calling 'rhs(lhs)'.


Name chunks in a single file

Description

Name unnamed chunks in a single file using the filename with extension stripped as basis.

Usage

name_chunks(path, unname = FALSE, prefix)

Arguments

path

Path to file

unname

Should all chunks be unnamed before naming? Default is 'FALSE'. Turning this option on will cause all existing labels to be overwritten. In contrast, with its default 'unname = FALSE' only unlabelled chunks will be named.

prefix

prefix to use to name chunks. Default to cleaned name of the Rmd.

Details

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

Value

Always returns TRUE invisibly. Called for side effects.

Examples

temp_file_path <- file.path(tempdir(), "test.Rmd")
file.copy(system.file("examples", "example1.Rmd", package = "namer"),
          temp_file_path,
          overwrite = TRUE)
name_chunks(temp_file_path)
if(interactive()){
file.edit(temp_file_path)
}
file.remove(temp_file_path)

Name chunks of all Rmds in a dir

Description

Name unnamed chunks in a dir using the filenames with extension stripped as basis.

Usage

name_dir_chunks(dir, unname = FALSE)

Arguments

dir

Path to folder

unname

Should all chunks be unnamed before naming? Default is 'FALSE'. Turning this option on will cause all existing labels to be overwritten. In contrast, with its default 'unname = FALSE' only unlabelled chunks will be named.

Details

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

Value

Always returns TRUE invisibly. Called for side effects.

Examples

temp_dir <- tempdir()
# just to make sure we're not overwriting
if(fs::dir_exists(file.path(temp_dir, "examples"))){
fs::dir_delete(file.path(temp_dir, "examples"))
}
fs::dir_copy(system.file("examples", package = "namer"),
            temp_dir)
 # this is an example file that'd fail
fs::file_delete(file.path(temp_dir,
                         "examples", "example4.Rmd"))
name_dir_chunks(temp_dir)
if(interactive()){
file.edit(file.path(temp_dir,
                   "examples", "example1.Rmd"))
}

Unname chunks in a single file

Description

Unname in a single file all chunks, or alternatively only unname the chunknames with a given prefix. In both cases, the chunk name "setup" is preserved, that chunk is never unnamed.

Usage

unname_chunks(path, chunk_name_prefix = NULL)

unname_all_chunks(path, chunk_name_prefix = NULL)

Arguments

path

Path to file

chunk_name_prefix

Character string with prefix of chunknames that will be removed. Default: NULL (indicating all chunknames will be removed except the one named 'setup')

Details

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

Value

Always returns TRUE invisibly. Called for side effects.

Examples

# remove all chunklabels except the one named 'setup'
temp_file_path <- file.path(tempdir(), "test1.Rmd")
file.copy(system.file("examples", "example4.Rmd", package = "namer"),
          temp_file_path,
          overwrite = TRUE)
unname_chunks(temp_file_path)
if(interactive()){
file.edit(temp_file_path)
}
# remove all chunk labels starting with 'example4'
temp_file_path <- file.path(tempdir(), "test2.Rmd")
file.copy(system.file("examples", "example4.Rmd", package = "namer"),
          temp_file_path,
          overwrite = TRUE)
unname_chunks(temp_file_path,chunk_name_prefix='example4')
if(interactive()){
file.edit(temp_file_path)
}

Unname chunks of all Rmds in a dir

Description

Name unnamed chunks in a dir using the filenames with extension stripped as basis.

Usage

unname_dir_chunks(dir)

Arguments

dir

Path to folder

Details

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

Value

Always returns TRUE invisibly. Called for side effects.

Examples

temp_dir <- tempdir()
# just to make sure we're not overwriting
if(fs::dir_exists(file.path(temp_dir, "examples"))){
fs::dir_delete(file.path(temp_dir, "examples"))
}
fs::dir_copy(system.file("examples", package = "namer"),
            temp_dir)
 # this is an example file that'd fail
fs::file_delete(file.path(temp_dir,
                         "examples", "example4.Rmd"))
name_dir_chunks(temp_dir)
if(interactive()){
file.edit(file.path(temp_dir,
                   "examples", "example1.Rmd"))
}