Writes a .clangd configuration file at path with CompileFlags set to
include headers from the system R installation and from common C++ interface
packages (Rcpp, RcppEigen, RcppArmadillo). If path is the root of an
R package (contains a DESCRIPTION file), an additional If: block is
appended that disables background indexing for the R/ source directory,
since it only contains R code, not C++ source. In that case .clangd is
also added to .Rbuildignore (inside a scoped project, so the active
project of the calling session is restored afterwards).
.clangdis the configuration file read by the clangd language server. It is typically placed in the project root.The system R include directory is obtained via
base::R.home()with component"include".Package include directories are obtained via
base::system.file()withpackage = <pkg>.Packages that are not installed (or that have no
include/directory) are skipped with acli::cli_warn()warning.
Usage
use_clangd(
path = NULL,
include = c("Rcpp", "RcppEigen", "RcppArmadillo"),
overwrite = FALSE,
open = rlang::is_interactive(),
...
)Arguments
- path
Character. Path to the directory where
.clangdshould be written. IfNULL(the default), the current working directory is used.- include
Character vector of package names whose
include/directories should be added toCompileFlags.Add. Defaults toc("Rcpp", "RcppEigen", "RcppArmadillo"). Passcharacter(0)to add only the system R include path. Custom names such as"BH"are supported; if the package is not installed, its include path is skipped and a warning is emitted.- overwrite
Logical. If
TRUE, overwrite an existing.clangdfile. Defaults toFALSE.- open
Logical. Whether to open the created file in the editor. Defaults to
rlang::is_interactive(). Only takes effect whenrstudioapiis installed.- ...
Must be empty. Reserved for future arguments.
Examples
# \donttest{
tmp <- tempdir()
use_clangd(path = tmp)
#> Warning: Package RcppEigen is not installed; skipping its include path.
#> Warning: Package RcppArmadillo is not installed; skipping its include path.
#> ✔ Created /tmp/RtmpvrXwDA/.clangd.
# Custom include library names
use_clangd(
path = tmp,
include = c("Rcpp", "BH"),
overwrite = TRUE
)
#> ! Overwriting /tmp/RtmpvrXwDA/.clangd.
#> Warning: Package BH is not installed; skipping its include path.
#> ✔ Created /tmp/RtmpvrXwDA/.clangd.
# }
