Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions doc/sphinx/source/community/code_documentation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,30 @@ R
~

Best practices for R code are described in `The tidyverse style
guide <https://style.tidyverse.org/>`__. We check adherence to this
style guide by using
`lintr <https://cran.r-project.org/web/packages/lintr/index.html>`__ on
CircleCI. Please use `styler <https://styler.r-lib.org/>`__ to
automatically format your code according to this style guide. In the
future we would also like to make use of
guide <https://style.tidyverse.org/>`__. We currently don't check adherence
to this, but we strongly encourage any new R diagnostic to be checked against the
style guide by using `lintr <https://cran.r-project.org/web/packages/lintr/index.html>`__.
Please use `styler <https://styler.r-lib.org/>`__ to automatically format your code according
to this style guide. To run these tools, uncomment these lines:

.. literalinclude:: ../../../../.pre-commit-config.yaml
:language: yaml
:start-at: # - repo: https://github.com/lorenzwalthert/precommit/ # Checks for R
:end-at: - id: lintr
:caption: R configuration in ``.pre-commit-config.yaml``.

and run the commands:

.. code-block:: bash

pre-commit run style-files --files esmvaltool/diag_scripts/your_script.R
pre-commit run lintr --files esmvaltool/diag_scripts/your_script.R

These pre-commit hooks have been disabled by default because over the past few
years all diagnostics that have been contributed were written in Python.
However, if R contributions pick up again, we would be happy to enable these
pre-commit hooks again.
In the future we would also like to make use of
`goodpractice <https://cran.r-project.org/web/packages/goodpractice/index.html>`__
to assess the quality of R code.

Expand Down
6 changes: 1 addition & 5 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ dependencies:

# R and dependencies
- cdo
- r-base >=3.5
- r-base >=4.4
- r-abind
- r-akima
- r-climdex.pcic
Expand All @@ -121,7 +121,3 @@ dependencies:
- r-spei
- r-udunits2
- r-yaml
# R packages needed for development
- r-git2r # dependency of lintr
- r-lintr ==3.1.2
- r-styler ==1.10.3
36 changes: 0 additions & 36 deletions tests/unit/test_lint.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
"""Lint tests."""

import os
import subprocess
import sys
import textwrap
from pathlib import Path

import pytest

import esmvaltool
from esmvaltool.utils.nclcodestyle import nclcodestyle

Expand Down Expand Up @@ -47,34 +42,3 @@ def test_nclcodestyle():
)

assert success, "Your NCL code does not follow our formatting standards."


@pytest.mark.installation
@pytest.mark.skipif(
sys.platform == "darwin",
reason="ESMValTool R not supported on OSX",
)
def test_r_lint(monkeypatch):
"""Test R lint."""
monkeypatch.setenv("LINTR_COMMENT_BOT", "FALSE")
package_root = os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
checker = os.path.join(package_root, "tests", "unit", "check_r_code.R")
try:
output = subprocess.check_output(
("Rscript", checker, package_root),
stderr=subprocess.STDOUT,
universal_newlines=True,
)
print(output)
return
except subprocess.CalledProcessError as ex:
print(
textwrap.dedent("""
Your R code does not follow our formatting standards.

Please fix the following issues:
"""),
)
print(ex.output)

assert False, "Your R code does not follow our formatting standards."