Error with R function using Knitr in Lyx

前端 未结 1 1023
陌清茗
陌清茗 2021-01-13 06:17

I am getting an error when using the summary() function using Knitr in Lyx. The functions preceding it works.

<<>>=
library(faraway)
head(teengam         


        
相关标签:
1条回答
  • 2021-01-13 06:26

    This problem has been solved in knitr after version 1.1. You do not need to change anything in LyX or R. Install knitr from CRAN:

    install.packages('knitr')
    

    Please ignore both answers below:


    I have finally found out the reason for this error (this is the deepest bug I have ever seen). It is because the upquote package does not work if the T1 encoding is declared after it is loaded, e.g.

    \documentclass{article}
    \usepackage{upquote}
    \usepackage[T1]{fontenc}
    \usepackage[latin9]{inputenc}
    \begin{document}
    \begin{verbatim}
    '
    \end{verbatim}
    \end{document}
    

    But if we move upquote after fontenc, it works:

    \documentclass{article}
    \usepackage[T1]{fontenc}
    \usepackage[latin9]{inputenc}
    \usepackage{upquote}
    \begin{document}
    \begin{verbatim}
    '
    \end{verbatim}
    \end{document}
    

    Or just do not use the T1 encoding -- uncheck the checkbox before the font encoding in the preferences:

    The reason that Ubuntu users were not able to reproduce the problem was because upquote.sty was from R's texmf tree instead of the one in TeXLive, and R's version of upquote works.

    The other way to fix the problem is to add R's texmf tree to MikTeX under Windows.

    Please ignore the answer below:


    Since options(show.signif.stars = FALSE) worked, I'm posting it as one possible answer, but this is still a very weird problem to me. Setting show.signif.stars = FALSE removes the significance codes from the results below (which was from summary(mdl)):

    Call:
    lm(formula = gamble ~ sex + status, data = teengamb)
    
    Residuals:
        Min      1Q  Median      3Q     Max 
    -35.873 -15.755  -3.007  10.924 111.586 
    
    Coefficients:
                Estimate Std. Error t value Pr(>|t|)    
    (Intercept)  60.2233    15.1347   3.979 0.000255 ***
    sex         -35.7094     9.4899  -3.763 0.000493 ***
    status       -0.5855     0.2727  -2.147 0.037321 *  
    ---
    Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 
    
    Residual standard error: 27.99 on 44 degrees of freedom
    Multiple R-squared: 0.2454, Adjusted R-squared: 0.2111 
    F-statistic: 7.154 on 2 and 44 DF,  p-value: 0.002042 
    

    The error came from the line Signif. codes, and I do not understand why any of these characters could possibly cause errors in LaTeX: all of them are ASCII and should work inside the verbatim environment.

    From the comments above, neither @mrdwab nor me could reproduce the problem. I guess there must be something weird about the OP's LaTeX installation.

    0 讨论(0)
提交回复
热议问题