Skip to content

Commit 9a86bfe

Browse files
committed
Merge branch 'main' (early part) into next
2 parents 50e7637 + 1942b33 commit 9a86bfe

File tree

8 files changed

+115
-8
lines changed

8 files changed

+115
-8
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ jobs:
7676
ref: ${{ inputs.ref }}
7777

7878
- name: Update status for rcc
79-
if: github.actor != 'github-copilot[bot]'
79+
if: github.actor != 'Copilot'
8080
# FIXME: Wrap into action
8181
env:
8282
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
@@ -182,7 +182,7 @@ jobs:
182182

183183
- name: Update status for rcc
184184
# FIXME: Wrap into action
185-
if: always() && (github.actor != 'github-copilot[bot]')
185+
if: always() && (github.actor != 'Copilot')
186186
env:
187187
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
188188
run: |
@@ -219,7 +219,7 @@ jobs:
219219

220220
- name: Update status for rcc (Copilot)
221221
# Update status directly when triggered by Copilot or bots, since they can't dispatch workflows
222-
if: always() && (github.actor == 'github-copilot[bot]')
222+
if: always() && (github.actor == 'Copilot')
223223
env:
224224
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
225225
run: |

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ cran
2424
/src/symbols.rds
2525
/tests/testthat/testthat-problems.rds
2626
/covr
27+
/.vscode/launch.json

AGENTS.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,16 @@ pak::pak(dependencies = "Config/Needs/build")
3131

3232
- When run on GitHub Actions, assume that R, the package in its current state and all dependencies are installed.
3333
- Only install new packages when needed for implementing new features or tests.
34-
- Run `R -q -e 'testthat::test_local(reporter = "check")'` to execute tests as a final step.
34+
- Run `R -q -e 'devtools::check()'` to execute all checks as a final step.
3535

3636
### Building and Testing
3737

3838
- Load package for development: `pkgload::load_all()`
3939
- Run tests: `testthat::test_local(reporter = "check")`
40+
- Run tests for a single file `test-foo.R`: `testthat::test_local(filter = "foo", reporter = "check")`
4041
- Build package: `devtools::build()`
4142
- Check package: `devtools::check()`
42-
- Update documentation: `devtools::document()`
43+
- Update `.Rd` documentation: `devtools::document()`
4344
- Format code: `air format .`
4445

4546
## Code Style and Documentation
@@ -54,22 +55,24 @@ pak::pak(dependencies = "Config/Needs/build")
5455
- Prefer expressive code over comments where possible
5556
- Add comments to utility functions that cannot be made immediately obvious
5657
- Focus comments on explaining the "why" and "how", the "what" should be clear from the code itself
57-
- Use line breaks after each sentence in multi-sentence comments
58+
- Use line breaks after each sentence
5859

5960
### R Code Conventions
6061

61-
- Follow the [tidyverse style guide](https://style.tidyverse.org)
62+
- Follow the [tidyverse style guide](https://style.tidyverse.org) and the [tidyverse design guide](https://design.tidyverse.org)
6263
- Use `snake_case` for new functions
6364
- Use explicit package prefixes (e.g., `withr::local_db_connection()`) for clarity
6465
- Maintain consistent indentation (2 spaces) and spacing patterns
6566
- Use meaningful variable names that reflect context
6667
- Run `air format .` before committing changes to ensure consistent formatting
68+
- Never change deprecated functions
6769

6870
### Documentation
6971

7072
- Use roxygen2 with Markdown syntax for all function documentation
7173
- Use math notation for formulas: `\eqn{...}` for inline, `\deqn{...}` for display equations
7274
- Keep each sentence on its own line in roxygen2 comments for better readability
75+
- Document all arguments and return values
7376
- Document internal functions using devtag (work in progress)
7477
- Link to C documentation using `@cdocs` tag: `#' @cdocs igraph_function_name`
7578
- Always run `devtools::document()` after updating documentation
@@ -84,7 +87,7 @@ All new functions must include:
8487

8588
- Examples
8689
- Tests
87-
- Proper documentation
90+
- Proper documentation, including arguments and return values
8891
- A concept so that it exists in the pkgdown reference index
8992
- An "experimental" badge via `r lifecycle::badge("experimental")`
9093

@@ -118,4 +121,7 @@ These are build artifacts that are regenerated automatically (see `src/README.md
118121
- Add test cases for all new functionality
119122
- For newly created autogenerated functions, always add a test to `test-aaa-auto.R`
120123
- Test file naming should mirror source file naming
124+
- Implement both structured and snapshot tests. For the latter, ensure stability by setting a random seed and calling `local_igraph_options(print.id = FALSE)` if graph IDs are involved.
125+
- When testing error behavior, prefer snapshot tests.
121126
- Run tests frequently during development and at the end: `testthat::test_local(reporter = "check")`
127+
- Run `devtools::check()` as a final step to ensure all checks pass.

NAMESPACE

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ export(induced_subgraph)
529529
export(infomap.community)
530530
export(interconnected.islands.game)
531531
export(intersection)
532+
export(invalidate_cache)
532533
export(is.bipartite)
533534
export(is.chordal)
534535
export(is.connected)

R/interface.R

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,35 @@ incident_edges <- function(graph, v, mode = c("out", "in", "all", "total")) {
714714

715715
res
716716
}
717+
718+
#' Invalidate the cache of a graph
719+
#'
720+
#' igraph graphs cache some basic properties (such as whether the graph is a
721+
#' DAG or whether it is simple) in an internal data structure for faster
722+
#' repeated queries. This function invalidates the cache, forcing a
723+
#' recalculation of the cached properties the next time they are needed.
724+
#'
725+
#' You should not need to call this function during normal usage; however, it
726+
#' may be useful for debugging cache-related issues. A tell-tale sign of an
727+
#' invalid cache entry is when the result of a cached function (such as
728+
#' \code{\link{is_dag}()} or \code{\link{is_simple}()}) changes after calling
729+
#' this function.
730+
#'
731+
#' @param graph The graph whose cache is to be invalidated.
732+
#' @return The graph with its cache invalidated. Since the graph is modified
733+
#' in place in R as well, you can also ignore the return value.
734+
#'
735+
#' @family low-level operations
736+
#'
737+
#' @export
738+
#' @examples
739+
#' g <- make_ring(10)
740+
#' # Cache is populated when calling is_simple()
741+
#' is_simple(g)
742+
#' # Invalidate cache (for debugging purposes)
743+
#' invalidate_cache(g)
744+
#' # Result should be the same
745+
#' is_simple(g)
746+
invalidate_cache <- function(graph) {
747+
invalidate_cache_impl(graph)
748+
}

_pkgdown.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@ reference:
113113
- running_mean
114114
- sample_seq
115115
- fit_power_law
116+
- subtitle: Low-level operations
117+
- contents:
118+
- has_concept("low-level operations")
116119
# [[[ network analysis start
117120
- title: Structural properties
118121
- contents:

man/invalidate_cache.Rd

Lines changed: 38 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-interface.R

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,29 @@ test_that("incident() works", {
229229
expect_snapshot(incident(g, 1))
230230
expect_snapshot(incident(g, 34))
231231
})
232+
233+
test_that("invalidate_cache works", {
234+
g <- make_ring(10)
235+
236+
# Cache is populated when calling is_simple()
237+
expect_true(is_simple(g))
238+
239+
# Invalidate cache
240+
result <- invalidate_cache(g)
241+
242+
# Result should be the same after cache invalidation
243+
expect_true(is_simple(result))
244+
245+
# Function should return a graph object
246+
expect_true(is_igraph(result))
247+
248+
# Graph properties should be preserved
249+
expect_equal(vcount(result), 10)
250+
expect_equal(ecount(result), 10)
251+
})
252+
253+
test_that("invalidate_cache errors on invalid input", {
254+
expect_error(invalidate_cache(NULL))
255+
expect_error(invalidate_cache("not a graph"))
256+
expect_error(invalidate_cache(123))
257+
})

0 commit comments

Comments
 (0)