Error in FUN(X[[i]], ...) : object 'variable' not found