RMarkdown knit fail when works in editor

A complete reproducible example, called a reprex will help draw other answers. You can cut and paste it from page 21 of the manual (there's no vignette).

library(bbmle)
#> Loading required package: stats4
    x <- 0:10
    y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8)
    d <- data.frame(x,y)
    ## we have a choice here: (1) don't impose boundaries on the parameters,
    ##  put up with warning messages about NaN values:
    fit1 <- mle2(y~dpois(lambda=ymax/(1+x/xhalf)),
         start=list(ymax=1,xhalf=1),
         data=d)
#> Warning in dpois(x = c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8), lambda =
#> c(15.9069797531213, : NaNs produced
#> Warning in dpois(x = c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8), lambda =
#> c(33.2333275588048, : NaNs produced
    p1 <- suppressWarnings(profile(fit1))
    plot(p1,main=c("first","second"),
         xlab=c(~y[max],~x[1/2]),ylab="Signed square root deviance",
         show.points=TRUE)

    suppressWarnings(confint(fit1)) ## recomputes profile
#>           2.5 %    97.5 %
#> ymax  17.885691 34.619764
#> xhalf  1.663451  6.479047
    confint(p1)  ## operates on existing profile
#>           2.5 %    97.5 %
#> ymax  17.885691 34.619764
#> xhalf  1.663451  6.479047
    suppressWarnings(confint(fit1,method="uniroot"))
#>           2.5 %   97.5 %
#> ymax  17.881505 34.61863
#> xhalf  1.661424  6.47848
    ## alternatively, we can use box constraints to keep ourselves
    ##  to positive parameter values ...
    fit2 <- update(fit1,method="L-BFGS-B",lower=c(ymax=0.001,xhalf=0.001))
    ## Not run:
    p2 <- profile(fit2)
    plot(p2,show.points=TRUE)

    ## but the fit for ymax is just bad enough that the spline gets wonky
    confint(p2)  ## now we get a warning
#>           2.5 %    97.5 %
#> ymax  17.885796 34.619764
#> xhalf  1.663472  6.479015
    confint(fit2,method="uniroot")
#>           2.5 %    97.5 %
#> ymax  17.881506 34.618626
#> xhalf  1.661407  6.478479
    ## bobyqa is a better-behaved bounded optimizer ...
    ##  BUT recent (development, 2012.5.24) versions of
    ##    optimx no longer allow single-parameter fits!
    if (require(optimx)) {
      fit3 <- update(fit1,
          optimizer="optimx",
          method="bobyqa",lower=c(ymax=0.001,xhalf=0.001))
       p3 <- profile(fit3)
       plot(p3,show.points=TRUE)
      confint(p3)
    }
#> Loading required package: optimx
#> Warning in library(package, lib.loc = lib.loc, character.only = TRUE,
#> logical.return = TRUE, : there is no package called 'optimx'

Created on 2019-03-11 by the reprex package (v0.2.1)

I was unable to reproduce the error on Mojave. The script runs identically in R console and in R Studio knitting to the distill (nee radix) template.