Skip to content

Commit 787a0f5

Browse files
committed
Add AGENTS.md
1 parent 98347d2 commit 787a0f5

2 files changed

Lines changed: 210 additions & 0 deletions

File tree

r/.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@ STYLE.md
3232
^inst/__pycache__$
3333
^bootstrap.R$
3434
air.toml
35+
AGENTS.md

r/AGENTS.md

Lines changed: 209 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,209 @@
1+
<!---
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing,
13+
software distributed under the License is distributed on an
14+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
KIND, either express or implied. See the License for the
16+
specific language governing permissions and limitations
17+
under the License.
18+
-->
19+
20+
# AI Agent Development Guidelines for the Arrow R Package
21+
22+
## Project Overview
23+
24+
The `arrow` R package provides an interface to the
25+
[Apache Arrow](https://arrow.apache.org/) C++ library. It lives at `r/` inside
26+
the `apache/arrow` monorepo, which also contains the C++ library (`cpp/`),
27+
Python (`python/`), and other language implementations.
28+
29+
This means:
30+
31+
- The R package depends on the C++ library built from `cpp/`.
32+
- Some bugs or features require changes in C++ (`cpp/`), not just R (`r/`).
33+
Fix problems at the right layer.
34+
- R functions often call C++ functions via bindings in `r/src/*.cpp`.
35+
36+
## AI Disclosure
37+
38+
Any pull request that used generative AI tools must disclose this. Include
39+
a note in the PR description stating which AI tools were used.
40+
41+
## Code Generation — Do Not Edit Generated Files
42+
43+
The files `r/R/arrowExports.R` and `r/src/arrowExports.cpp` are
44+
**auto-generated** by `r/data-raw/codegen.R`. Never edit them manually — your
45+
changes will be silently overwritten.
46+
47+
To expose a C++ function to R:
48+
49+
1. Add the function to a `.cpp` file in `r/src/` with the `// [[arrow::export]]`
50+
annotation above it.
51+
2. Use the naming convention `ClassName__methodName` (double underscore), e.g.:
52+
53+
```cpp
54+
// [[arrow::export]]
55+
std::shared_ptr<arrow::DataType> Int8__initialize() {
56+
return arrow::int8();
57+
}
58+
```
59+
60+
3. Run `r/data-raw/codegen.R` to regenerate the export files (this also runs
61+
automatically during package configure when `ARROW_R_DEV=true`).
62+
4. The R side can then call `Int8__initialize()` directly.
63+
64+
Other generated files that should not be edited by hand:
65+
66+
- `r/R/dplyr-funcs-doc.R` — generated documentation
67+
- `r/man/*.Rd` — generated by roxygen2 (edit the roxygen comments in `r/R/*.R`
68+
instead, then run `make doc`)
69+
70+
## Development Setup
71+
72+
### Loading and Building
73+
74+
```r
75+
# Load the package for interactive development (from the r/ directory)
76+
devtools::load_all()
77+
```
78+
79+
### Documentation
80+
81+
After modifying roxygen2 comments in any `r/R/*.R` file, regenerate
82+
documentation:
83+
84+
```bash
85+
# From the r/ directory
86+
make doc
87+
```
88+
89+
This runs code formatting (via pre-commit), generates documentation helpers,
90+
runs roxygen2, and stages the updated `.Rd` files. Always do this before
91+
committing documentation changes.
92+
93+
### Code Formatting
94+
95+
The package uses the [air](https://posit-dev.github.io/air/) formatter
96+
configured in `r/air.toml` (line width 120, excludes generated files). Run
97+
formatting via pre-commit:
98+
99+
```bash
100+
# From the r/ directory — format only changed files
101+
make style
102+
103+
# Format all files
104+
make style-all
105+
```
106+
107+
The full R pre-commit suite (lint, format, C++ format, C++ lint):
108+
109+
```bash
110+
pre-commit run --show-diff-on-failure --color=always --all-files r
111+
```
112+
113+
### Testing
114+
115+
Tests use testthat (edition 3). Test files live in `r/tests/testthat/` and
116+
follow the naming convention `test-<topic>.R`, with shared helpers in
117+
`helper-*.R` files.
118+
119+
```r
120+
# Run all tests
121+
devtools::test()
122+
123+
# Run tests for a single file (e.g., test-array.R)
124+
devtools::test(filter = "array")
125+
```
126+
127+
```bash
128+
# Full R CMD check
129+
make check
130+
```
131+
132+
### Package Check
133+
134+
```r
135+
devtools::check()
136+
```
137+
138+
## Code Style
139+
140+
Follow the [tidyverse style guide](https://style.tidyverse.org/). See also
141+
`r/STYLE.md` for documentation-specific conventions.
142+
143+
- Use `snake_case` for functions and arguments.
144+
- The base pipe `|>` does not support the `.` placeholder inside braces the way
145+
`%>%` does. Use explicit function parameters instead.
146+
147+
## File Structure
148+
149+
| Path | Contents |
150+
|------|----------|
151+
| `r/R/*.R` | R source code |
152+
| `r/src/*.cpp` | C++ bindings (using cpp11) |
153+
| `r/src/arrowExports.cpp` | **Generated** — do not edit |
154+
| `r/R/arrowExports.R` | **Generated** — do not edit |
155+
| `r/data-raw/codegen.R` | Code generation script |
156+
| `r/data-raw/docgen.R` | Documentation generation script |
157+
| `r/tests/testthat/test-*.R` | Test files |
158+
| `r/tests/testthat/helper-*.R` | Shared test helpers |
159+
| `r/man/*.Rd` | **Generated** — edit roxygen comments in `r/R/`, then `make doc` |
160+
| `r/vignettes/` | Package vignettes |
161+
162+
## Pull Requests
163+
164+
### Title Format
165+
166+
```
167+
GH-<issue-number>: [R] <description>
168+
```
169+
170+
For example: `GH-49607: [R] Add AGENTS.md file to R package`
171+
172+
### PR Description
173+
174+
Use all four template sections:
175+
176+
```markdown
177+
### Rationale for this change
178+
179+
[1-2 sentences: why is this change needed?]
180+
181+
### What changes are included in this PR?
182+
183+
[1-2 sentences: what was changed?]
184+
185+
### Are these changes tested?
186+
187+
[How the changes were tested]
188+
189+
### Are there any user-facing changes?
190+
191+
[Yes/No with brief explanation]
192+
```
193+
194+
Do not skip any section.
195+
196+
## Git Workflow
197+
198+
This project uses a fork-based workflow:
199+
200+
- **Push to your fork** (`origin`), never directly to `upstream`
201+
(`apache/arrow`).
202+
- **Create PRs** from your fork to `upstream/main`.
203+
- Fetch latest upstream before creating a branch:
204+
205+
```bash
206+
git fetch upstream
207+
git checkout upstream/main
208+
git checkout -b GH-<issue>-description
209+
```

0 commit comments

Comments
 (0)