GitNexus/gitnexus/test/fixtures/sample-code/simple.r
Mick Cooney f90484c296 test(r): add R grammar and sample-code coverage
Add sample-code/simple.r and an R block in tree-sitter-languages covering
function, S4, and R6 definitions, library()/source() imports, and free,
member, namespaced, and native-pipe calls. List simple.r in the parsing
fixture-existence check and add R extension detection to ingestion-utils.
2026-10-01 13:37:57 +01:00

39 lines
756 B
R

library(R6)
source("helpers.R")
#' Add two numbers.
#' @param a numeric first operand
#' @param b numeric second operand
#' @export
add <- function(a, b) {
a + b
}
private_helper <- function() {
0
}
setClass("Point", representation(x = "numeric", y = "numeric"))
setGeneric("distance", function(obj, other) standardGeneric("distance"))
setMethod("distance", "Point", function(obj, other) {
abs(obj@x - other@x) + abs(obj@y - other@y)
})
Counter <- R6::R6Class("Counter",
public = list(
count = 0,
increment = function() {
self$count <- self$count + 1
invisible(self)
}
)
)
run <- function() {
counter <- Counter$new()
counter$increment()
c(1, 2, 3) |> add(4) |> private_helper()
stats::median(c(1, 2, 3))
}