I am using a simple for loop to calculate some mathematical formula. Eventually i want to see results on a web route. So for that i started using plumber, but it is showing an error. The R script looks like:
postgres.R
#* Get the progress of the script
#* @get /progress
# #* @param s
# library(plumber)
require(svMisc)
n <- 2 ^ 20
inside <- 0
total <- 0
function(){
for (i in 1:100){
x <- runif(n)
y <- runif(n)
r <- x ^ 2 + y ^ 2
inside <- inside + sum(r <= 1)
total <- total + n
# print(inside * 4 / total)
progress(i)
if(i == 100) message("\nDone!")
}
message("function executed!")
}
I am running this using the commands:
library(plumber)
r<-plumb("postgres.R")
and getting this error in RStudio console:
Error in throw_if_func_is_not_a_function(private$func) :
`expr` did not evaluate to a function