Infected < c(1,3,4,7,7,7,7,9,31,45,66,73,84,89,99,117,190,217,319,340,368,399,439,466,498,590,649,694,767,824,886,966,1156)
SIR < function(time, state, parameters) {
par < as.list(c(state, parameters))
with(par, {
dS < beta/N * I * S
dI < beta/N * I * S  gamma * I
dR < gamma * I
list(c(dS, dI, dR))
})
}
library(deSolve)
init < c(S = NInfected[1], I = Infected[1], R = 0)
RSS < function(parameters) {
names(parameters) < c("beta", "gamma")
out < ode(y = init, times = Day, func = SIR, parms = parameters)
fit < out[ , 3]
sum((Infected  fit)^2)
}
Opt < optim(c(0.5, 0.5), RSS, method = "LBFGSB", lower = c(0, 0), upper = c(1, 1))
Opt_par < setNames(Opt$par, c("beta", "gamma"))
Opt_par
t < 1:190 # time in days
fit < data.frame(ode(y = init, times = t, func = SIR, parms = Opt_par))

When I run the code the following Warning message appears " debug location is approximate because source is not available"

"Error in setNames(Opt$par, c("beta", "gamma")) : object 'Opt' not found" also appears.
Does anyone know how to solve this problem?