According to this blog , optional arguments without defaults are missing from the inside of the function. Testing for it returns TRUE .
foo <- function(mat, j){ v <- sum(mat[,j]); print(missing(j)) v } foo(mat = matrix(1:4,3,4)) [1] TRUE [1] 30
Not knowing what the features are, I experimented a bit with sum , and this is what it shows.
sum(matrix(1:4,3,4)[,NA]) [1] NA sum(matrix(1:4,3,4)[,NULL]) [1] 0 sum(matrix(1:4,3,4)[,]) [1] 30
If we do not specify any index for the matrix, sum sums all its values.
From reading the blog and a little experiment, I believe that your custom functions work when the functional processes used provide data and can work with missing arguments. In the case of a subset of the matrix, the behavior with missing arguments for the subsets is that the function performs an operation on the entire data set.
source share