Closed larryshamalama closed 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!"
Closes bullet point 2 of #1.
This PR is missing two elements, albeit they are not urgent:
Simplification ofsf
function to "`singledispatch'' akin in Python