Kuan-Liu-Lab / causens

An R package for causal sensitivity analysis methods
https://kuan-liu-lab.github.io/causens/
MIT License
1 stars 0 forks source link

Extending current work for linear c functions #25

Closed larryshamalama closed 10 months ago

larryshamalama commented 11 months ago

Closes bullet point 2 of #1.

This PR is missing two elements, albeit they are not urgent:

larryshamalama commented 10 months ago

Single dispatching of sf can be done in a separate PR. Tip: use R's S3 method which is similar to Python's singledispatching:

# Define the generic function
my_function <- function(x, ...) {
  UseMethod("my_function")
}

# Define the method for numeric vectors
my_function.numeric <- function(x, ...) {
  sum(x)
}

# Define the method for character vectors
my_function.character <- function(x, ...) {
  paste(x, collapse = " ")
}

# Test the function with a numeric vector
print(my_function(c(1, 2, 3)))  # Prints 6

# Test the function with a character vector
print(my_function(c("Hello", "world!")))  # Prints "Hello world!"