Hi,
The documentation for writing extensions is very nice. However I find it hard to grasp the details of creating extensions. Would it be possible to add a very simple, but complete, extension example to the docs?
1. Lets say I wanted to create a meanTrim function that takes a vector as argument and trims off the min and max values first. i.e.
meanTrim <- function(x) {
x <- x[x != max(x)]
x <- x[x != min(x)]
return(mean(x))
}
# Example:
vec <- c(2.3, 2.7, 3.1, 4.9, 1.0, 2.4, 2.6, 2.1, 2.0, 1.9)
print(mean(vec))
print(meanTrim(vec))
2. A more involved example would be something where I have a java class that does something useful and i want to take advantage of that in an R function
e.g. i have the Java class
public class StringTransformer {
/** strips off any non numeric char from the string. */
public static String toNumber(String txt) {
StringBuilder result = new StringBuilder();
txt.chars().mapToObj( i -> (char)i )
.filter( c -> Character.isDigit(c) ).forEach( c -> result.append(c) );
return result.toString();
}
}
and I want to make a library which has a function called makeNumeric which uses the StringTransformer.toNumber() functionality.
3. Lets say i want to override (mask) existing functionality .e.g i want to override library() with something that guesses the correct package so i can do e.g. library("dplyr") and get the same thing as if I would have written library("org.renjin.cran:dplyr"), what do i need to do to make that happen?
If you answer here, I'd be happy to type up a tutorial and submit a patch suggestion to the docs.
Best regards,
Per