Repository navigation
add Agents MD file #298
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
Merged
Merged
add Agents MD file #298
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
790f6f9
chore: add first version of CLAUDE.md
f1a471b
docs: add full intstructions to CLAUDE.Rmd
2e980f1
chore: update config for verified commits
osenan e70a4fb
[skip style] [skip vbump] Restyle files
github-actions[bot] 1fafbb6
chore: update config for verified commits
osenan d4b4213
chore: include the CLAUDE.md in the Rbuildignore
osenan 36461ec
chore: fix markdown style
osenan 77f24d2
chore: modify intro sentence to avoid warnings in the template
osenan f76fad3
Update CLAUDE.Rmd
osenan 7230557
refactor, use AGENTS.Rmd within vignettes instead of CLAUDE.Rmd
osenan d125368
refactor: improve the way we render AGENTS.md
osenan aaa259c
docs: include information about debugging qenvs
osenan 103a690
docs: improve sections on related packages and debugging
osenan 37691bb
chore: fix typo
osenan f1b9525
refactor: generalize removal of optional sections
osenan 83916fa
[skip style] [skip vbump] Restyle files
github-actions[bot] fc7ccde
chore: add CLAUDE.md so it looks at AGENTS.md
osenan eafde42
chore: fix lint markdown error
osenan 94d73e9
add local user name to approve CLA
osenan 04ce27c
fix: remove CI errors
osenan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,250 @@ | ||
|
|
||
| # teal.code R Package Development Guide | ||
|
|
||
| ## Package Overview | ||
|
|
||
| `teal.code` is an R package for storing code and its execution | ||
| environment in objects called `qenv`. It supports reproducible code | ||
| execution in teal Shiny applications. Developers can inspect and modify | ||
| `qenv` objects, providing full control over the stored code and | ||
| environment. These objects also capture warnings and errors | ||
| automatically. | ||
|
|
||
| ## Development Context | ||
|
|
||
| The teal framework uses Shiny to create reproducible environments for | ||
| data analysis. Within this framework, `teal.code` manages code and its | ||
| execution environment. Related packages include: | ||
|
|
||
| - `teal.data`: Stores all data objects, data relations and | ||
| transformations of data used in teal applications, in an object called | ||
| `teal_data`. The `teal_data` object inherits from the `qenv` and | ||
| therefore shares all properties about code reproducibility. | ||
| - `teal`: Provides the core architecture for teal Shiny applications. | ||
| Teal modules should use `teal_data` objects to ensure that code | ||
| changes are recorded and reproducible. | ||
| - `teal.reporter`: Integrates reports with reproducible code in teal | ||
| applications. Its reporter functions accept `teal_data` objects as | ||
| inputs and extend this class. | ||
|
|
||
| For an introduction to `qenv` and its related functions and methods, see | ||
| @vignettes/qenv.Rmd. | ||
|
|
||
| ### Workflows | ||
|
|
||
| - When creating a `qenv`, favor readability over concise code. | ||
| - For simple `qenv` objects, favor `within()`, as it supports more | ||
| readable code. | ||
| - When creating a `qenv` that uses functions with side effects, such as | ||
| `runif()`, `library` or `options` always use `eval_code()`. Use the | ||
| appropriate comment to link side effects to objects | ||
| - For a complex `qenv`, consider dividing the work into smaller `qenv` | ||
| objects that encapsulate distinct logical steps. | ||
| - In the line of the previous comment, `qenv` can be combined with | ||
| method `c.qenv`. Be careful that they cannot have elements with the | ||
| same name and about the combined order of code execution. | ||
| - For a long or complex `qenv`, choose between `eval_code()` and | ||
| `within()` based on: | ||
| - the number of external variables added to the `qenv`; a larger | ||
| number favors `eval_code()`; | ||
| - how often the same external variable is used; greater repetition | ||
| favors `within()`. | ||
| - When creating custom functions within a teal app server, it is better | ||
| to do define them inside a qenv. If defined outside the function might | ||
| fail. | ||
| - When fixing bugs or adding features, avoid changing the core | ||
| principles of `qenv`. Check whether an issue already exists. If the | ||
| expected behavior is unclear, request that an issue be created before | ||
| making changes that could have unexpected consequences. | ||
|
|
||
| ### Debugging `qenv` | ||
|
|
||
| Errors in teal applications commonly occur while a `qenv` is being | ||
| evaluated. By default, `qenv` handles these errors and returns an object | ||
| of class `qenv.error`. This prevents the teal application from crashing | ||
| immediately and provides the user with a helpful error message. | ||
|
|
||
| After identifying the problematic `qenv`, use the following steps to | ||
| investigate it: | ||
|
|
||
| - Use the `qenv.error` message to identify the line of code that | ||
| triggered the error. | ||
| - If that line alone does not explain the error, inspect the preceding | ||
| code. If necessary, create a temporary version of the `qenv` | ||
| containing only the preceding calls, or modify the line that triggered | ||
| the error. | ||
| - Inspect values stored in the `qenv` using `qenv[["my_value"]]` to help | ||
| identify the source of the error. | ||
| - Because messages and warnings produced by a `qenv` are not printed to | ||
| the R console, inspect them using `get_messages()` and | ||
| `get_warnings()`. | ||
| - The same techniques for inspecting values, messages, and warnings can | ||
| be used when a `qenv` produces incorrect results without raising an | ||
| error. | ||
|
|
||
| <!-- markdownlint-disable-file MD002 MD041 --> | ||
|
|
||
| This package is part of the teal framework. The following configuration | ||
| applies to all packages within the teal framework. | ||
|
|
||
| ## Package Structure and Organization | ||
|
|
||
| ### Key Directories | ||
|
|
||
| Follow the standard R package structure with teal-specific conventions: | ||
|
|
||
| ``` text | ||
| package_name/ | ||
| ├── .github # CI/CD workflows | ||
| ├── R/ # R source code | ||
| ├── tests/testthat/ # Unit tests using testthat | ||
| ├── vignettes/ # Long-form documentation | ||
| ├── inst/ # Package assets | ||
| ├── AGENTS.md # Development guide for AI agents (this file) | ||
| ├── DESCRIPTION # Package metadata | ||
| ├── NAMESPACE # Exports and imports | ||
| ├── NEWS.md # Change log | ||
| ├── README.md # Package overview | ||
| ├── _pkgdown.yml # Documentation website config | ||
| ├── .lintr # Linting configuration | ||
| └── .Rbuildignore # Build exclusions | ||
| ``` | ||
|
|
||
| ### Naming Conventions | ||
|
|
||
| - **Function names**: Use `snake_case` consistently | ||
| - **Class names**: Use `PascalCase` (e.g., `TealAppDriver`) | ||
| - **Module functions**: Prefix UI functions with `ui_` and server | ||
| functions with `srv_` | ||
| - **Internal functions**: Use descriptive names without export | ||
|
|
||
| ### File Organization | ||
|
|
||
| - **One main function per file** when the function is substantial | ||
| - **Group related utilities** in shared files (e.g., `utils.R`, | ||
| `validations.R`) | ||
| - **Module files**: Use pattern `tm_<name>.R` for teal modules | ||
| - **Helper functions**: Prefix with the main function they support | ||
|
|
||
| ## Code Style and Standards | ||
|
|
||
| ### Code Quality | ||
|
|
||
| - **Run `pre-commit` hooks**: Always run `pre-commit run --all-files` | ||
| before committing, Fix any issues it reports - the error messages are | ||
| informative and will guide you. It automatically checks code style, | ||
| documentation and other quality issues. If pre-commit is not | ||
| available, run the checks manually. Lint the R code manually as well | ||
| if not called by pre-commit. | ||
| - **Follow `tidyverse` style**: General R code style follows the | ||
| `tidyverse` style guide. | ||
| - **Documentation**: All exported functions must have `roxygen2` | ||
| documentation with `@returns` and `@examples` fields. | ||
| - **Formatting** rules are configured in the `.lintr` file. | ||
|
|
||
| ## Dependencies and Imports | ||
|
|
||
| ### Dependency Management | ||
|
|
||
| - **Minimize dependencies**: Only add dependencies that provide | ||
| significant value | ||
| - **Version constraints**: Specify minimum versions for critical | ||
| dependencies | ||
| - **Ecosystem coherence**: Prefer packages already used within teal | ||
| ecosystem | ||
|
|
||
| ### Import Best Practices | ||
|
|
||
| Avoid importing package functions via roxygen2 (`#' @import pkg`)tags in | ||
| favor of explicit namespacing for clarity when appropriate. When needed | ||
| prefer specific imports over full package imports. | ||
|
|
||
| ## Testing Framework | ||
|
|
||
| ### Testing Philosophy | ||
|
|
||
| - **Test public functions only**: Internal utilities should be tested | ||
| through public interfaces | ||
| - **Precise, focused tests**: Each test should verify one specific | ||
| behavior | ||
| - **High coverage**: Maintain at least 80% test coverage as measured by | ||
| `covr` | ||
| - **Integration over units**: Test realistic usage patterns | ||
| - **Test Dependencies**.: Add | ||
| `testthat::skip_if_not_installed(package_name)` only for dependencies | ||
| in `Suggests` or related to tests cases | ||
|
|
||
| ### Shiny Module Testing | ||
|
|
||
| - **Server functions**: Test with `shiny::testServer()` | ||
| - **UI functions**: Test basic usage with regular testing (class checks, | ||
| error generation, snapshots, regexp search). Test UI scenarios and | ||
| interactions with `teal:::TealAppDriver` (based on | ||
| `shinytest2::AppDriver`) for integration testing | ||
| - **Reactive behavior**: Test reactive chains and side effects | ||
|
|
||
| ### Test Organization and Naming | ||
|
|
||
| - **One test file per R file**: `test-module_example.R` for | ||
| `module_example.R` | ||
| - **Descriptive test names**: Clearly describe what is being tested | ||
| - **End to end test names**: `test-shinytest2-module_example.R` for | ||
| `module_example.R` | ||
| - **Logical grouping**: Group related tests using `describe()` and | ||
| individual tests with `it()` when beneficial | ||
| - **Test data**: Create minimal test datasets, avoid external | ||
| dependencies | ||
|
|
||
| ## Documentation and Communication | ||
|
|
||
| ### Package Documentation | ||
|
|
||
| - **`README.md`**: Clear overview, installation, basic usage examples | ||
| - **Vignettes**: Comprehensive guides for complex functionality | ||
| - **Function documentation**: All exported functions must have | ||
| `roxygen2` documentation | ||
| - **`NEWS.md`**: Detailed changelog of features, bugs and miscellanea | ||
| changes affecting the users | ||
|
|
||
| ### Package Version Management | ||
|
|
||
| Do not change versions on your own. There is a CI/CD workflow that | ||
| manages the versions automatically on the `main` branch. | ||
|
|
||
| ## CI/CD and Development Workflow | ||
|
|
||
| Prefer to reuse templates from r.pkg.template. Main checks in place are: | ||
|
|
||
| - `check.yaml`: R CMD check, unit tests, coverage | ||
| - `docs.yaml`: Documentation building and deployment | ||
| - `audit.yaml`: Security and dependency auditing | ||
| - `pkgdown.yaml`: Website generation | ||
|
|
||
| ## Quality Assurance | ||
|
|
||
| ### Code Quality Metrics | ||
|
|
||
| - **Test Coverage**: ≥80% line coverage | ||
| - **Linting**: No lint violations using configured `.lintr` | ||
| - **Documentation**: 100% of exports documented | ||
|
|
||
| ### Code Review Process | ||
|
|
||
| - **Pull Request Reviews**: All changes require human review and | ||
| approval | ||
| - **Automated Checks**: CI must pass before merging | ||
| - **Breaking Changes**: Require special consideration and communication | ||
| - **Documentation Updates**: Must accompany functional changes | ||
|
|
||
| ### Performance Considerations | ||
|
|
||
| - **Shiny Reactivity**: Minimize unnecessary reactive computations | ||
| - **Data Processing**: Use efficient data manipulation patterns | ||
| - **Memory Usage**: Consider memory implications for large datasets | ||
| - **Loading Time**: Optimize package loading and module initialization | ||
|
|
||
| ## Maintenance Guidelines | ||
|
|
||
| - **Long-term Support**: Maintain backward compatibility when possible | ||
| - **Dependencies**: Minimal and justified dependencies only | ||
| - **Deprecation**: Use `lifecycle` package for function deprecation |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| # teal.code R Package Development Guide | ||
|
|
||
| The content is at @AGENTS.md |
|
llrs-roche marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| --- | ||
| # This file generates AGENTS.md in the package root. | ||
| # It is not part of the package build or the pkgdown site. | ||
| # To regenerate it, run from the package root: | ||
| # rmarkdown::render("vignettes/_AGENTS.Rmd", output_file = file.path("AGENTS.md"), output_dir = ".") | ||
| output: | ||
| github_document: | ||
| html_preview: false | ||
| params: | ||
| url: "https://raw.githubusercontent.com/insightsengineering/teal/refs/heads/main/SHARED_AGENTS.md" | ||
| --- | ||
| # teal.code R Package Development Guide | ||
|
|
||
| ```{r setup, include=FALSE} | ||
| knitr::opts_chunk$set(echo = TRUE) | ||
| ``` | ||
|
|
||
| ## Package Overview | ||
|
|
||
| `teal.code` is an R package for storing code and its execution environment in objects called `qenv`. | ||
| It supports reproducible code execution in teal Shiny applications. Developers can inspect and modify `qenv` objects, | ||
| providing full control over the stored code and environment. These objects also capture warnings and errors automatically. | ||
|
|
||
| ## Development Context | ||
|
|
||
| The teal framework uses Shiny to create reproducible environments for data analysis. Within this framework, `teal.code` | ||
| manages code and its execution environment. Related packages include: | ||
|
|
||
| - `teal.data`: Stores all data objects, data relations and | ||
| transformations of data used in teal applications, in an object called | ||
| `teal_data`. The `teal_data` object inherits from the `qenv` and therefore | ||
| shares all properties about code reproducibility. | ||
| - `teal`: Provides the core architecture for teal Shiny applications. | ||
| Teal modules should use `teal_data` objects to ensure that code changes are | ||
| recorded and reproducible. | ||
| - `teal.reporter`: Integrates reports with reproducible code in teal | ||
| applications. Its reporter functions accept `teal_data` objects as inputs and | ||
| extend this class. | ||
|
|
||
| For an introduction to `qenv` and its related functions and methods, see @vignettes/qenv.Rmd. | ||
|
|
||
| ### Workflows | ||
|
|
||
| - When creating a `qenv`, favor readability over concise code. | ||
| - For simple `qenv` objects, favor `within()`, as it supports more readable code. | ||
| - When creating a `qenv` that uses functions with side effects, such as `runif()`, `library` or `options` always use `eval_code()`. Use the appropriate comment to link side effects to objects | ||
| - For a complex `qenv`, consider dividing the work into smaller `qenv` objects that encapsulate distinct logical steps. | ||
| - In the line of the previous comment, `qenv` can be combined with method `c.qenv`. Be careful that they cannot have elements with | ||
| the same name and about the combined order of code execution. | ||
| - For a long or complex `qenv`, choose between `eval_code()` and `within()` based on: | ||
| - the number of external variables added to the `qenv`; a larger number favors `eval_code()`; | ||
| - how often the same external variable is used; greater repetition favors `within()`. | ||
| - When creating custom functions within a teal app server, it is better to do define them inside a qenv. If defined outside | ||
| the function might fail. | ||
| - When fixing bugs or adding features, avoid changing the core principles of `qenv`. Check whether an issue already exists. If the expected behavior is unclear, request that an issue be created before making changes that could have | ||
| unexpected consequences. | ||
|
|
||
| ### Debugging `qenv` | ||
|
|
||
| Errors in teal applications commonly occur while a `qenv` is being evaluated. By default, `qenv` handles these errors | ||
| and returns an object of class `qenv.error`. This prevents the teal application from crashing immediately and provides | ||
| the user with a helpful error message. | ||
|
|
||
| After identifying the problematic `qenv`, use the following steps to investigate it: | ||
|
|
||
| - Use the `qenv.error` message to identify the line of code that triggered the error. | ||
| - If that line alone does not explain the error, inspect the preceding code. If necessary, create a temporary version | ||
| of the `qenv` containing only the preceding calls, or modify the line that triggered the error. | ||
| - Inspect values stored in the `qenv` using `qenv[["my_value"]]` to help identify the source of the error. | ||
| - Because messages and warnings produced by a `qenv` are not printed to the R console, inspect them using | ||
| `get_messages()` and `get_warnings()`. | ||
| - The same techniques for inspecting values, messages, and warnings can be used when a `qenv` produces incorrect | ||
| results without raising an error. | ||
|
|
||
| ```{r teal_content, echo=FALSE, results='asis'} | ||
| # Append common shared instructions from teal framework | ||
| common_agents_url <- params$url | ||
| common_agents_path <- tempfile() | ||
| download.file(url = common_agents_url, destfile = common_agents_path, quiet = TRUE) | ||
| common_agents_shared <- readLines(common_agents_path) | ||
| # remove optional sections | ||
| remove_sections <- c("<!-- (Begins|Ends) Module Section") | ||
| Reduce( | ||
| function(x, y) { | ||
| delim <- grep(y, x) | ||
| if (length(delim) == 0) { | ||
| return(x) | ||
| } else if (length(delim) != 2) { | ||
| stop("Section delimiters are not balanced") | ||
| } | ||
| x[-1 * seq(from = delim[1], to = delim[2])] | ||
| }, | ||
| remove_sections, | ||
| init = common_agents_shared | ||
| ) |> | ||
| cat(sep = "\n") | ||
| ``` |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.