> For the complete documentation index, see [llms.txt](https://docs.sonarsource.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/languages/r.md).

# R

Language-specific information about how SonarQube Server 2026.5 supports the analysis of R.

## Analysis overview

Sonar analyzes R so the same quality gates and governance extend to the code behind your most consequential decisions. R analysis supports reliability and maintainability rules, code metrics, copy-paste detection, and secrets scanning.

* **R rules**: reliability and maintainability rules in the built-in Sonar way quality profiles
* **Scripts and notebooks analyzed together**: `.R` files and the R chunks inside R Markdown files are both analyzed
* **Duplication detection**: copy-paste detection across your R code
* **lintr import**: import lintr findings alongside Sonar issues
* **covr coverage import**: import test coverage reports emitted by covr

**Get started:** if the project is already analyzed by SonarQube Server, your R code appears in the next analysis.

## What you get

Every analysis of R code produces:

* Issues from the rules enabled in the **Sonar way core** profile (or another built-in profile, if assigned).
* Standard metrics: lines of code, comment density, functions, classes, statements, and cognitive complexity.
* Duplication blocks: DRY violations across your R code become a number you can track in a quality gate.
* Syntax highlighting in the code viewer.

To see or change which rules run, go to **Quality Profiles** > **R** > **Sonar way core** (or another built-in profile). To customize, extend or copy the profile, then assign it to your R projects.

## Embedded R code

In R Markdown files, the analyzer considers R code chunks as embedded R code. A code chunk starts with ` ```{r} ` or ` ```{r, opts} `, where `opts` represents optional chunk options.

All R code chunks in a single R Markdown file are analyzed as one unit because code chunks share context by default. For example, if the same string literal is duplicated in multiple chunks in the same file, SonarQube Server reports that duplication.

Some R rules are not run on embedded R code because they are not appropriate for R Markdown files or would produce excessive noise.

Syntax errors in the Markdown portion of an R Markdown file are reported as R parsing errors.

## Importing external issues from lintr

You can import issue reports from the R linting tool [lintr](https://lintr.r-lib.org/) using the `sonar.r.lintr.reportPaths` analysis property.

This property expects JSON reports in GitLab's Code Quality report format. Generate compatible reports with lintr's [`gitlab_output`](https://lintr.r-lib.org/reference/gitlab_output.html) output function.

The file paths in the reports must be relative to the directory configured with the `sonar.sources` property. For configuration details, see [External analyzer reports](/sonarqube-server/analyzing-source-code/importing-external-issues/external-analyzer-reports.md).

## Importing test coverage reports

You can import R test coverage reports in either of the following formats:

* **Cobertura format:** Set the `sonar.r.cobertura.reportPaths` property.
* **Generic test coverage format:** Set the `sonar.coverageReportPaths` property. See [Generic test data](/sonarqube-server/analyzing-source-code/test-coverage/generic-test-data.md).

The widely used R coverage tool [covr](https://covr.r-lib.org/) supports both SonarQube's generic coverage format and the Cobertura format. See [Test coverage parameters](/sonarqube-server/analyzing-source-code/test-coverage/test-coverage-parameters.md#r) for R coverage-property details.

## Troubleshooting

### R shows zero lines of code

If **Measures** > **Size** shows no R row at all, your files are not being recognized as R. Check that the extensions are `.R`, `.r`, or `.Rmd`, then go to **Administration** > **General Settings** > **Analysis Scope** and confirm that `sonar.exclusions` does not match your R paths.

If **Measures** > **Size** shows R with 0 lines, the files were found but contain no analyzable code. Confirm that you are looking at the right branch.

### A rule fires in your .R file but not in your .Rmd chunk

Rules about file or script structure are disabled for embedded R. Rules that would be noisy or meaningless inside a notebook chunk are excluded from embedded R analysis by design.

### A parsing error points at prose, not code, in your .Rmd

Syntax errors in the Markdown portion of an R Markdown file surface as R parsing errors. Fix the malformed Markdown, usually an unterminated code fence, and re-analyze.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sonarsource.com/sonarqube-server/analyzing-source-code/languages/r.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
