I am currently working with the latest version of R.NET (version 1.5.14.13671) and when I use the onboarding examples described above, or whenever I call the engine from a WebAPI or web project I am getting an error where it can't find a function, usually the ones in the stats package. It fails even when I am trying to load the stats package.
I am running a pretty simple script:
# Goal: Show the efficiency of the mean when compared with the median
# using a large simulation where both estimators are applied on
# a sample of U(0,1) uniformly distributed random numbers.
one.simulation <- function(N=100) { # N defaults to 100 if not supplied
x <- runif(N)
return(c(mean(x), median(x)))
}
The web example provided, if I can make it work, is PERFECT for what I'm try to do which is to execute an RScript (maybe map some variables into and out of it) and then collect the results and even the images. But I can't seem to find where the issue is happening to anyone else. I also verified the script runs in the R GUI. So if it's running in a windows application or the R GUI, it's fine, but if it runs as a web service, web API or from a Web Site - It's not recognizing the functions or packages correctly. It's as if it parses them incorrectly.
Any thoughts or ideas that anyone has would be greatly appreciated!
sehunley
# Simulation --
results <- replicate(100000, one.simulation(20)) # Gives back a 2x100000 matrix
# Two kernel densities --
k1 <- density(results[1,]) # results[1,] is the 1st row
k2 <- density(results[2,])
# A pretty picture --
xrange <- range(k1$x, k2$x)
plot(k1$x, k1$y, xlim=xrange, type="l", xlab="Estimated value", ylab="")
grid()
lines(k2$x, k2$y, col="red")
abline(v=.5)
legend(x="topleft", bty="n",
lty=c(1,1),
col=c("black", "red"),
legend=c("Mean", "Median"))
↧