How to avoid NaN in optim?

Suppose, I have a function and want to optimize it. But if I use optim() which gives warnings(). How can I avoid these warnings of NaN?

myfun<-function(par, x){

f<- sum(x)*length(x)+sum(log(gamma(par))*x)+1
return(-f)
}
optim(0.1, myfun, x=c(1,5,4,7,8,5,6,5,45,8))

$par [1] 4.203895e-46$value
[1] -10762.39
$counts function gradient 502 NA$convergence
[1] 1

-