在R Studio中调试。如何设置编辑器断点

时间:2015-08-27 16:17:11

标签: r debugging rstudio breakpoints

我是R(R Studio)的新手,我试图找出调试器的工作原理。 当我在代码中间设置编辑器断点时,R完全忽略它并执行整个事情。

我如何在此for循环中间设置一个断点来调试?

seed <- 1337
set.seed(seed)

nn    <- c(10,50,100,500,1000)
E_hat <- matrix(0,length(nn),1)
E     <- matrix(0,length(nn),1)

for (i in 1:length(nn)) {

        N     <- nn[i]
        mu    <- 0
        sigma <- 1

        # The phi function we want to integrate
        phi <- function(u) {exp(u)}

        # Draw random uniform numbers
        uni <- matrix(runif(N),N,1)

        # Convert to Gaussian PDF
        u <- mu + sigma*qnorm(uni,mu,sigma)

        # Take arithmetic average over the phi function
        E_hat[i] <- 1/N * sum(phi(u))

        # Analytical mean of log-normal distribution
        E[i] <- exp(mu+sigma^2/2)

        print(sprintf("-----------------------------------)"))
        print(sprintf("Results with N = %.4f", N))
        print(sprintf("Simulated mean %.4f", E_hat[i]))
        print(sprintf("Analytical mean %.4f", E[i]))
        print(sprintf("Difference %.4f", E_hat[i]-E[i]))
        print(sprintf("-----------------------------------)"))

}

0 个答案:

没有答案