Skip to content

Commit 8e25a2d

Browse files
authored
Merge branch 'main' into copilot/autogenerate-callback-functions
2 parents 10aeac2 + c4a2c33 commit 8e25a2d

38 files changed

Lines changed: 411 additions & 184 deletions

.github/copilot-instructions.md

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,33 @@
22

33
> **Note**: For general development guidelines, code style conventions, and AI agent instructions, see [`AGENTS.md`](../AGENTS.md) in the repository root.
44
5+
## Project Overview
6+
7+
igraph/rigraph is an R package for network analysis and graph theory with a C/C++ backend.
8+
59
## Common Commands for Copilot Chat
610

711
- Load for development: `pkgload::load_all()`
812
- Run tests: `testthat::test_local(reporter = "check")`
13+
- Run tests for a single file: `testthat::test_local(filter = "foo", reporter = "check")`
914
- Format code: `air format .`
1015
- Update documentation: `devtools::document()`
16+
- Build package: `devtools::build()`
17+
- Check package: `devtools::check()`
18+
19+
## Key Conventions
20+
21+
- Use `snake_case` for functions and arguments
22+
- Follow tidyverse style guide
23+
- Use roxygen2 with Markdown for documentation
24+
- Run `air format .` before committing
25+
- Add tests for all new functionality
26+
- Use explicit package prefixes (e.g., `withr::local_db_connection()`)
27+
28+
## Important Files
29+
30+
- **Do not modify directly**: `src/rinterface.c`, `R/aaa-auto.R` (generated by Stimulus)
31+
- Update generated files: `make -f Makefile-cigraph src/rinterface.c R/aaa-auto.R`
32+
- See `tools/README.md` for Stimulus framework guidelines
1133

12-
Refer to `AGENTS.md` for more instructions.
34+
Refer to `AGENTS.md` for complete instructions.

.github/workflows/copilot-setup-steps.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ on:
66
workflow_dispatch:
77
push:
88
paths:
9-
- .github/workflows/copilot-setup-steps.yml
9+
- .github/workflows/copilot-setup-steps.yaml
1010
pull_request:
1111
paths:
12-
- .github/workflows/copilot-setup-steps.yml
12+
- .github/workflows/copilot-setup-steps.yaml
1313

1414
jobs:
1515
# The job MUST be called `copilot-setup-steps` or it will not be picked up by Copilot.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ cran
2727
/.vscode/launch.json
2828
/Rplots.pdf
2929
/_codeql_detected_source_root
30+
tests/testthat/_problems/

R/assortativity.R

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ assortativity_legacy <- function(
237237

238238
#' @param types Vector giving the vertex types. They as assumed to be integer
239239
#' numbers, starting with one. Non-integer values are converted to integers
240-
#' with [as.integer()].
240+
#' with [as.integer()]. Character vectors are converted to integers using
241+
#' [as.factor()].
241242
#' @rdname assortativity
242243
#' @export
243244
#' @cdocs igraph_assortativity_nominal
@@ -247,6 +248,11 @@ assortativity_nominal <- function(
247248
directed = TRUE,
248249
normalized = TRUE
249250
) {
251+
# Convert character types to factor then to integer for categorical data
252+
if (is.character(types)) {
253+
types <- as.integer(as.factor(types))
254+
}
255+
250256
assortativity_nominal_impl(
251257
graph = graph,
252258
types = types,

R/utils.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,23 @@ modify_list <- function(x, y) {
9494

9595
utils::modifyList(x, y)
9696
}
97+
98+
#' Test function to verify error formatting with file and line information
99+
#'
100+
#' @description
101+
#' This is a test function that throws an error from C code with file and line
102+
#' information.
103+
#' The error message should include the source file and line number where the
104+
#' error occurred.
105+
#'
106+
#' @return This function never returns; it always throws an error.
107+
#' @keywords internal
108+
#' @noRd
109+
#' @examples
110+
#' \dontrun{
111+
#' # This will throw an error with source location information
112+
#' test_error_with_source()
113+
#' }
114+
test_error_with_source <- function() {
115+
.Call(Rx_igraph_test_error_with_source)
116+
}

man/assortativity.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/assortativity.nominal.Rd

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/cpp11.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -602,6 +602,7 @@ extern SEXP Rx_igraph_st_vertex_connectivity(SEXP, SEXP, SEXP);
602602
extern SEXP Rx_igraph_star(SEXP, SEXP, SEXP);
603603
extern SEXP Rx_igraph_subcomponent(SEXP, SEXP, SEXP);
604604
extern SEXP Rx_igraph_subisomorphic_lad(SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP);
605+
extern SEXP Rx_igraph_test_error_with_source(void);
605606
extern SEXP Rx_igraph_transitivity_local_undirected_all(SEXP, SEXP);
606607
extern SEXP Rx_igraph_union(SEXP, SEXP);
607608
extern SEXP Rx_igraph_vcount(SEXP);
@@ -1200,6 +1201,7 @@ static const R_CallMethodDef CallEntries[] = {
12001201
{"Rx_igraph_star", (DL_FUNC) &Rx_igraph_star, 3},
12011202
{"Rx_igraph_subcomponent", (DL_FUNC) &Rx_igraph_subcomponent, 3},
12021203
{"Rx_igraph_subisomorphic_lad", (DL_FUNC) &Rx_igraph_subisomorphic_lad, 7},
1204+
{"Rx_igraph_test_error_with_source", (DL_FUNC) &Rx_igraph_test_error_with_source, 0},
12031205
{"Rx_igraph_transitivity_local_undirected_all", (DL_FUNC) &Rx_igraph_transitivity_local_undirected_all, 2},
12041206
{"Rx_igraph_union", (DL_FUNC) &Rx_igraph_union, 2},
12051207
{"Rx_igraph_vcount", (DL_FUNC) &Rx_igraph_vcount, 1},

src/rinterface_extra.c

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2315,6 +2315,18 @@ static inline const char* maybe_add_punctuation(const char* msg, const char* pun
23152315
return is_punctuated(msg) ? "" : punctuation;
23162316
}
23172317

2318+
/* Strip vendor/cigraph/src/ prefix from file path. This prefix depends on the
2319+
* build procedure, namely on the directory that the compiler is invoked from. */
2320+
static inline const char* simplify_file_path(const char *file) {
2321+
const char prefix[] = "vendor/cigraph/src/";
2322+
const size_t prefix_len = sizeof(prefix) - 1;
2323+
2324+
if (strncmp(file, prefix, prefix_len) == 0) {
2325+
return file + prefix_len;
2326+
}
2327+
return file;
2328+
}
2329+
23182330
void Rx_igraph_fatal_handler(const char *reason, const char *file, int line) {
23192331
#ifdef IGRAPH_SANITIZER_AVAILABLE
23202332
__sanitizer_print_stack_trace();
@@ -2336,10 +2348,12 @@ void Rx_igraph_error_handler(const char *reason, const char *file,
23362348
* IGRAPH_FINALLY_FREE() can then clean it up. */
23372349

23382350
if (Rx_igraph_errors_count == 0 || !Rx_igraph_in_r_check) {
2351+
const char* simplified_path = simplify_file_path(file);
23392352
snprintf(Rx_igraph_error_reason, sizeof(Rx_igraph_error_reason),
2340-
"At %s:%i : %s%s %s", file, line, reason,
2341-
maybe_add_punctuation(reason, ","),
2342-
igraph_strerror(igraph_errno));
2353+
"%s%s %s\nSource: %s:%i", reason,
2354+
maybe_add_punctuation(reason, "."),
2355+
igraph_strerror(igraph_errno),
2356+
simplified_path, line);
23432357
Rx_igraph_error_reason[sizeof(Rx_igraph_error_reason) - 1] = 0;
23442358

23452359
// FIXME: This is a hack, we should replace all memory allocations in the
@@ -2356,8 +2370,10 @@ void Rx_igraph_error_handler(const char *reason, const char *file,
23562370

23572371
void Rx_igraph_warning_handler(const char *reason, const char *file, int line) {
23582372
if (Rx_igraph_warnings_count == 0) {
2373+
const char* simplified_path = simplify_file_path(file);
23592374
snprintf(Rx_igraph_warning_reason, sizeof(Rx_igraph_warning_reason),
2360-
"At %s:%i : %s%s", file, line, reason, maybe_add_punctuation(reason, "."));
2375+
"%s%s\nSource: %s:%i", reason, maybe_add_punctuation(reason, "."),
2376+
simplified_path, line);
23612377
Rx_igraph_warning_reason[sizeof(Rx_igraph_warning_reason) - 1] = 0;
23622378
}
23632379
Rx_igraph_warnings_count++;

src/sources-glue-c.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
GLUE_C_SOURCES=rcallback.o rinterface.o rinterface_extra.o rrandom.o uuid.o
1+
GLUE_C_SOURCES=rcallback.o rinterface.o rinterface_extra.o rrandom.o test_error_with_source.o uuid.o

0 commit comments

Comments
 (0)