Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pre-commit config so formatR can be used as a remote hook #101

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
^renv$
^renv\.lock$
inst/examples
.gitignore
^\.Rproj\.user$
Expand Down
2 changes: 2 additions & 0 deletions .Rprofile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Sys.setenv(RENV_CONFIG_AUTO_SNAPSHOT = "FALSE")
source("renv/activate.R")
8 changes: 8 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
- id: formatr
name: formatR
description: Uses formatR to format R files
entry: Rscript scripts/pre-commit-formatR.R
language: r
types: [text]
Serene-Arc marked this conversation as resolved.
Show resolved Hide resolved
files: '.*.[rR]$'
additional_dependencies: [docopt]
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,20 @@ to

[![R source code after
reformatting](https://db.yihui.org/imgur/TBZm0B8.png)](https://yihui.shinyapps.io/formatR/)

## Pre-commit Hook

formatR is available as a pre-commit hook. The following arguments are available:

```
Options:
--no-comments Remove comments.
--no-blanks Remove blank lines.
--arrow If given, arrows will not be substituted for = signs.
--pipe If given, pipes will not be changed.
--brace-newline If given, braces will not be put on new lines.
--indent=INDENT Number of indents. [default: 4]
--no-wrap Skip wrapping the text.
--width-cutoff=WIDTH Text width cutoff. [default: 80]
--args-newline If TRUE, arguments are started on a new line after a function call. [default: FALSE]
```
23 changes: 23 additions & 0 deletions renv.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"R": {
"Version": "4.3.3",
"Repositories": [
{
"Name": "CRAN",
"URL": "https://cran.csiro.au"
}
]
},
"Packages": {
"renv": {
"Package": "renv",
"Version": "1.0.5",
"Source": "Repository",
"Repository": "CRAN",
"Requirements": [
"utils"
],
"Hash": "32c3f93e8360f667ca5863272ec8ba6a"
}
}
}
7 changes: 7 additions & 0 deletions renv/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
library/
local/
cellar/
lock/
python/
sandbox/
staging/
Loading
Loading