lintr-compatible linters for box modules in R
box.linters
is an R package that provides the {lintr}
package compatibility with {box}
package modules. In addition to providing code-styling checks for box::use()
function calls, box.linters
includes a collection of linter functions to replace lintr::object_usage_linter()
.
While the primary purpose of box.linters is for use with the {rhino}
package, its functions and features are available for use with any R code or project that uses the box package for modular R code.
Motivation
lintr::object_usage_linter
is not compatible with box modules.
# use of box modules
box::use(
stringr[...]
)
some_function <- function() {
str_trim(" String with trailing and leading white space\t")
}
> lintr::lint(box-module.R)
<text>:6:3: warning: [object_usage_linter] no visible global function definition for 'str_trim'
str_trim(" String with trailing and leading white space ")
^~~~~~~~
In order to use lintr
and box
together, it was necessary to disable lintr::object_usage_linter()
:
lintr::lint(box-module.R,
linters = lintr::linters_with_defaults(object_usage_linter = NULL))
However, this meant we lose the functionality provided by lintr::object_usage_linter()
.
Installation
Stable version:
install.packages("box.linters")
Development version:
# install.packages("remotes")
remotes::install_github("Appsilon/box.linters")
Usage
Create a configuration file and run selected linters:
.lintr setup
# create a .lintr file
box.linters::use_box_lintr()
# a file:
lintr::lint(filename.R)
# in a project:
lintr::lint_dir()
Manually
Or, use box.linters
manually with lintr
:
# a file:
lintr::lint(filename.R, linters = box.linters::box_default_linters)
# in a project:
lintr::lint_dir(linters = box.linters::box_default_linters)
{glue} String Interpolation
box.linters also looks inside glue strings. The default opening and closing delimiters are “{
” and “}
”. glue provides a way to customize delimiters. Support for custom glue delimiters are provided project-wide by setting glue.open
and glue.close
options in the following manner:
This is consistent with glue::glue()
, doubling the full delimiter escapes it.
Because setting glue.open
and glue.close
will be global or project-wide, it is advised to invoke glue
in the following manner to avoid confusion:
Contribute
If you want to contribute to this project, please submit a regular PR, once you’re done with the new feature or bug fix.
Reporting a bug is also helpful - please use Github issues and describe your problem as detailed as possible.
Appsilon
Appsilon is a Posit (formerly RStudio) Full Service Certified Partner.
Learn more at appsilon.com.
Get in touch opensource@appsilon.com
Explore the Rhinoverse - a family of R packages built around Rhino!