Using a custom error function when training / creating a Neural Network

Hello, I want to train a Neural Network and pass it a custom error measure function.

For example, I tried the following:

rmse = function(error) sqrt(mean(error ^ 2))
nn <- neuralnet(score ~ ., data = ds_trn_noc, hidden = 2, err.fct = rmse)

but got the following error:

Error in eval(expr) : generic 'function' is not a function

My goal is that when I run the command:

> nn$result.matrix

I get the following output:

##                                         [,1]
## error                           1.988157e+02
## reached.threshold               9.903357e-03
## steps                           4.576900e+04
...
...
...

where the error is calculated by my custom function: rmse.

Any idea about what's wrong on my code above?

Thanks!

@Yarnabrina I got the same error after using your recommended function.

Yes, I just realised it and hence deleted my earlier post. See the comments here:

@Yarnabrina, is there maybe any chance that this was working before but not now with current versions? I tried that code as well and I got the following error:

Error in calculate.gradients(weights = weights, length.weights = length.weights,  : 
  dims [product 16] do not match the length of object [32]

Is it working for you that code on StackOverflow?

Thanks!