mirror of
https://github.com/abhigyanpatwari/GitNexus.git
synced 2026-10-17 04:33:45 +00:00
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.
39 lines
756 B
R
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))
|
|
}
|