I am using R with knittr and LaTeX. I have isolated some error that has been occuring the following block:

opt_vals <- data.frame(opt_length=numeric(2000),
for (i in 1:2000){
  sim_fit <- fitted(model2)+rnorm(18, 0, sd(stdres2))
  sim_data <- data.frame(sim_fit, 
                       length2=data_set$length2 )

  model4 <- lm(sim_fit ~ length + length2, data = sim_data)

  #Optimale laengde
  optimal_length <- -coef(model4)[2]/(2*coef(model4)[3])

  opt_vals$opt_length[i] <- optimal_length

  #Maximalt forventede aeg
  max_expected_eggs <- coef(model4)[1]-

  opt_vals$opt_eggs[i] <- max_expected_eggs

Whenever I include this code in my Knittr document, I get errors about a missing (or extra) $ or a forgotten }

Additional info: When I set <>= the error disappear so I think it's something in the typesetting, but I am not at all sure about how to fix it.

Edit: I am attaching an screenshot of the errors and code region.

Screen shot of errors and code

Any help is appreciated!

  • 1
    Knits without a problem, and compiles without any errors at all. However the pdf output tells me that 'model2' is missing. Run on Win10, with updated MikTex 2.9, and R 3.1.3 installations. Mar 7 '17 at 16:49
  • 1
    I think the last part of your comment was lost :)
    – msx
    Mar 7 '17 at 16:51
  • 1
    @R.Schumacher That is very odd... I have attached an image showing the errors.
    – msx
    Mar 7 '17 at 17:56
  • 1
    Did you actually run the knitr command in R on the *.Rnw file. Mar 7 '17 at 22:16
  • I run it from R-studio.
    – msx
    Mar 7 '17 at 22:28

It seems something in knitr typesetting is incompatible with the mathtime pro 2 fonts, removing that solves the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.