diff --git a/doc/sphinx/source/community/code_documentation.rst b/doc/sphinx/source/community/code_documentation.rst index 82bd72dbfb..819cc3371c 100644 --- a/doc/sphinx/source/community/code_documentation.rst +++ b/doc/sphinx/source/community/code_documentation.rst @@ -274,12 +274,30 @@ R ~ Best practices for R code are described in `The tidyverse style -guide `__. We check adherence to this -style guide by using -`lintr `__ on -CircleCI. Please use `styler `__ to -automatically format your code according to this style guide. In the -future we would also like to make use of +guide `__. 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 `__. +Please use `styler `__ 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 `__ to assess the quality of R code. diff --git a/environment.yml b/environment.yml index 780e4664e4..6975ce8a86 100644 --- a/environment.yml +++ b/environment.yml @@ -96,7 +96,7 @@ dependencies: # R and dependencies - cdo - - r-base >=3.5 + - r-base >=4.4 - r-abind - r-akima - r-climdex.pcic @@ -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 diff --git a/tests/unit/test_lint.py b/tests/unit/test_lint.py index afaf3ae730..296bea0197 100644 --- a/tests/unit/test_lint.py +++ b/tests/unit/test_lint.py @@ -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 @@ -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."